@@ -87,15 +87,19 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
8787 // warn before deleting config
8888 var haveProceedAnswer bool
8989 for ! haveProceedAnswer {
90- term .Write ([]byte ("Warning: This will delete all auth contexts. Continue (yes/[no])?: " ))
90+ if _ , err = term .Write ([]byte ("Warning: This will delete all auth contexts. Continue (yes/[no])?: " )); err != nil {
91+ return
92+ }
9193 proceedBytes , readErr := term .ReadLine ()
9294 if readErr != nil {
9395 err = readErr
9496 return
9597 }
9698 proceedString := cast .ToString (proceedBytes )
9799 if proceedString != "yes" && proceedString != "no" && proceedString != "" {
98- term .Write ([]byte ("invalid input.\n " ))
100+ if _ , err = term .Write ([]byte ("invalid input.\n " )); err != nil {
101+ return
102+ }
99103 continue
100104 }
101105
@@ -119,7 +123,9 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
119123 userInputExitEarly := make (chan bool )
120124 userInputContext := make (chan cmdTypes.AuthContext )
121125
122- term .Write ([]byte ("\n To exit early, type 'exit' or send EOF (ctrl+d)\n \n " ))
126+ if _ , err = term .Write ([]byte ("\n To exit early, type 'exit' or send EOF (ctrl+d)\n \n " )); err != nil {
127+ return
128+ }
123129
124130 // start context add loop
125131 go func () {
@@ -139,7 +145,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
139145
140146 // context name
141147 for ! haveContextNameAnswer {
142- term .Write ([]byte ("Name this context: " ))
148+ if _ , err := term .Write ([]byte ("Name this context: " )); err != nil {
149+ userInputError <- err
150+ break WHILEMOREADDS
151+ }
143152 contextNameBytes , err := term .ReadLine ()
144153 if err != nil {
145154 userInputError <- err
@@ -150,7 +159,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
150159 userInputExitEarly <- true
151160 break WHILEMOREADDS
152161 } else if contextNameAnswer == "" {
153- term .Write ([]byte ("context name cannot be blank.\n " ))
162+ if _ , err := term .Write ([]byte ("context name cannot be blank.\n " )); err != nil {
163+ userInputError <- err
164+ break WHILEMOREADDS
165+ }
154166 } else {
155167 haveContextNameAnswer = true
156168 context .ContextName = contextNameAnswer
@@ -159,7 +171,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
159171
160172 // username
161173 for ! haveUsernameAnswer {
162- term .Write ([]byte ("LiquidWeb username: " ))
174+ if _ , err := term .Write ([]byte ("LiquidWeb username: " )); err != nil {
175+ userInputError <- err
176+ break WHILEMOREADDS
177+ }
163178 usernameBytes , err := term .ReadLine ()
164179 if err != nil {
165180 userInputError <- err
@@ -170,7 +185,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
170185 userInputExitEarly <- true
171186 break WHILEMOREADDS
172187 } else if usernameAnswer == "" {
173- term .Write ([]byte ("username cannot be blank.\n " ))
188+ if _ , err := term .Write ([]byte ("username cannot be blank.\n " )); err != nil {
189+ userInputError <- err
190+ break WHILEMOREADDS
191+ }
174192 } else {
175193 haveUsernameAnswer = true
176194 context .Username = usernameAnswer
@@ -189,7 +207,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
189207 userInputExitEarly <- true
190208 break WHILEMOREADDS
191209 } else if passwordAnswer == "" {
192- term .Write ([]byte ("password cannot be blank.\n " ))
210+ if _ , err := term .Write ([]byte ("password cannot be blank.\n " )); err != nil {
211+ userInputError <- err
212+ break WHILEMOREADDS
213+ }
193214 } else {
194215 havePasswordAnswer = true
195216 context .Password = passwordAnswer
@@ -198,7 +219,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
198219
199220 // make current context?
200221 for ! haveMakeCurrentContextAnswer {
201- term .Write ([]byte ("Make current context? ([yes]/no)" ))
222+ if _ , err := term .Write ([]byte ("Make current context? ([yes]/no)" )); err != nil {
223+ userInputError <- err
224+ break WHILEMOREADDS
225+ }
202226 makeCurrentContextBytes , err := term .ReadLine ()
203227 if err != nil {
204228 userInputError <- err
@@ -210,7 +234,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
210234 break WHILEMOREADDS
211235 }
212236 if makeCurrentContextString != "" && makeCurrentContextString != "yes" && makeCurrentContextString != "no" {
213- term .Write ([]byte ("invalid input.\n " ))
237+ if _ , err := term .Write ([]byte ("invalid input.\n " )); err != nil {
238+ userInputError <- err
239+ break WHILEMOREADDS
240+ }
214241 continue
215242 }
216243
@@ -222,7 +249,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
222249
223250 // more contexts to add ?
224251 for ! haveMoreContextsToAddAnswer {
225- term .Write ([]byte ("Add another context? (yes/[no]): " ))
252+ if _ , err := term .Write ([]byte ("Add another context? (yes/[no]): " )); err != nil {
253+ userInputError <- err
254+ break WHILEMOREADDS
255+ }
226256 moreContextsBytes , err := term .ReadLine ()
227257 if err != nil {
228258 userInputError <- err
@@ -235,7 +265,10 @@ func fetchAuthDataInteractively() (writeConfig bool, err error) {
235265 break WHILEMOREADDS
236266 }
237267 if answer != "" && answer != "yes" && answer != "no" {
238- term .Write ([]byte ("invalid input.\n " ))
268+ if _ , err := term .Write ([]byte ("invalid input.\n " )); err != nil {
269+ userInputError <- err
270+ break WHILEMOREADDS
271+ }
239272 continue
240273 }
241274
@@ -287,7 +320,9 @@ WAIT:
287320 case complete := <- userInputComplete :
288321 if complete {
289322 // wipe the config for a clean slate.
290- writeEmptyConfig ()
323+ if err := writeEmptyConfig (); err != nil {
324+ lwCliInst .Die (err )
325+ }
291326 cfgFile , cfgPathErr := getExpectedConfigPath ()
292327 if cfgPathErr != nil {
293328 err = cfgPathErr
@@ -301,12 +336,16 @@ WAIT:
301336 if err != nil {
302337 lwCliInst .Die (err )
303338 }
304- f .Close ()
339+ if err := f .Close (); err != nil {
340+ lwCliInst .Die (err )
341+ }
305342 if err := os .Chmod (cfgFile , 0600 ); err != nil {
306343 lwCliInst .Die (err )
307344 }
308345
309- lwCliInst .Viper .ReadConfig (bytes .NewBuffer ([]byte {}))
346+ if err := lwCliInst .Viper .ReadConfig (bytes .NewBuffer ([]byte {})); err != nil {
347+ lwCliInst .Die (err )
348+ }
310349 }
311350
312351 // set Viper config from contexts slice
@@ -366,7 +405,9 @@ func writeEmptyConfig() error {
366405 if err != nil {
367406 return err
368407 }
369- f .Close ()
408+ if err := f .Close (); err != nil {
409+ return err
410+ }
370411
371412 if err := os .Chmod (cfgFile , 0600 ); err != nil {
372413 return err
0 commit comments