@@ -3,8 +3,6 @@ package cmdio
33import (
44 "bufio"
55 "context"
6- "encoding/json"
7- "errors"
86 "fmt"
97 "io"
108 "os"
@@ -17,7 +15,7 @@ import (
1715
1816// This is the interface for all io interactions with a user
1917type Logger struct {
20- // Mode for the logger. One of (append, json ).
18+ // Mode for the logger. One of (append).
2119 Mode flags.ProgressLogFormat
2220
2321 // Input stream (eg. stdin). Answers to questions prompted using the Ask() method
@@ -121,10 +119,6 @@ func splitAtLastNewLine(s string) (string, string) {
121119}
122120
123121func (l * Logger ) AskSelect (question string , choices []string ) (string , error ) {
124- if l .Mode == flags .ModeJson {
125- return "" , errors .New ("question prompts are not supported in json mode" )
126- }
127-
128122 // Promptui does not support multiline prompts. So we split the question.
129123 first , last := splitAtLastNewLine (question )
130124 _ , err := l .Writer .Write ([]byte (first ))
@@ -150,10 +144,6 @@ func (l *Logger) AskSelect(question string, choices []string) (string, error) {
150144}
151145
152146func (l * Logger ) Ask (question , defaultVal string ) (string , error ) {
153- if l .Mode == flags .ModeJson {
154- return "" , errors .New ("question prompts are not supported in json mode" )
155- }
156-
157147 // Add default value to question prompt.
158148 if defaultVal != "" {
159149 question += fmt .Sprintf (` [%s]` , defaultVal )
@@ -180,34 +170,9 @@ func (l *Logger) Ask(question, defaultVal string) (string, error) {
180170 return ans , nil
181171}
182172
183- func (l * Logger ) writeJson (event Event ) {
184- b , err := json .MarshalIndent (event , "" , " " )
185- if err != nil {
186- // we panic because there we cannot catch this in jobs.RunNowAndWait
187- panic (err )
188- }
189- _ , _ = l .Writer .Write (b )
190- _ , _ = l .Writer .Write ([]byte ("\n " ))
191- }
192-
193- func (l * Logger ) writeAppend (event Event ) {
194- _ , _ = l .Writer .Write ([]byte (event .String ()))
195- _ , _ = l .Writer .Write ([]byte ("\n " ))
196- }
197-
198173func (l * Logger ) Log (event Event ) {
199174 l .mutex .Lock ()
200175 defer l .mutex .Unlock ()
201- switch l .Mode {
202- case flags .ModeJson :
203- l .writeJson (event )
204-
205- case flags .ModeAppend :
206- l .writeAppend (event )
207-
208- default :
209- // we panic because errors are not captured in some log sides like
210- // jobs.RunNowAndWait
211- panic ("unknown progress logger mode: " + l .Mode .String ())
212- }
176+ _ , _ = l .Writer .Write ([]byte (event .String ()))
177+ _ , _ = l .Writer .Write ([]byte ("\n " ))
213178}
0 commit comments