@@ -54,9 +54,6 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
5454 $ gh auth login
5555 # => do an interactive setup
5656
57- $ gh auth login --web
58- # => open a browser to authenticate and do a non-interactive setup
59-
6057 $ gh auth login --with-token < mytoken.txt
6158 # => read token from mytoken.txt and authenticate against github.com
6259
@@ -174,34 +171,32 @@ func loginRun(opts *LoginOptions) error {
174171
175172 existingToken , _ := cfg .Get (hostname , "oauth_token" )
176173
177- if existingToken != "" {
174+ if existingToken != "" && opts . Interactive {
178175 err := client .ValidateHostCfg (hostname , cfg )
179176 if err == nil {
180177 apiClient , err := client .ClientFromCfg (hostname , cfg )
181178 if err != nil {
182179 return err
183180 }
184181
185- if opts .Interactive {
186- username , err := api .CurrentLoginName (apiClient , hostname )
187- if err != nil {
188- return fmt .Errorf ("error using api: %w" , err )
189- }
190- var keepGoing bool
191- err = prompt .SurveyAskOne (& survey.Confirm {
192- Message : fmt .Sprintf (
193- "You're already logged into %s as %s. Do you want to re-authenticate?" ,
194- hostname ,
195- username ),
196- Default : false ,
197- }, & keepGoing )
198- if err != nil {
199- return fmt .Errorf ("could not prompt: %w" , err )
200- }
182+ username , err := api .CurrentLoginName (apiClient , hostname )
183+ if err != nil {
184+ return fmt .Errorf ("error using api: %w" , err )
185+ }
186+ var keepGoing bool
187+ err = prompt .SurveyAskOne (& survey.Confirm {
188+ Message : fmt .Sprintf (
189+ "You're already logged into %s as %s. Do you want to re-authenticate?" ,
190+ hostname ,
191+ username ),
192+ Default : false ,
193+ }, & keepGoing )
194+ if err != nil {
195+ return fmt .Errorf ("could not prompt: %w" , err )
196+ }
201197
202- if ! keepGoing {
203- return nil
204- }
198+ if ! keepGoing {
199+ return nil
205200 }
206201 }
207202 }
@@ -273,15 +268,15 @@ func loginRun(opts *LoginOptions) error {
273268 }
274269
275270 gitProtocol = strings .ToLower (gitProtocol )
276- }
277271
278- fmt .Fprintf (opts .IO .ErrOut , "- gh config set -h %s git_protocol %s\n " , hostname , gitProtocol )
279- err = cfg .Set (hostname , "git_protocol" , gitProtocol )
280- if err != nil {
281- return err
282- }
272+ fmt .Fprintf (opts .IO .ErrOut , "- gh config set -h %s git_protocol %s\n " , hostname , gitProtocol )
273+ err = cfg .Set (hostname , "git_protocol" , gitProtocol )
274+ if err != nil {
275+ return err
276+ }
283277
284- fmt .Fprintf (opts .IO .ErrOut , "%s Configured git protocol\n " , utils .GreenCheck ())
278+ fmt .Fprintf (opts .IO .ErrOut , "%s Configured git protocol\n " , utils .GreenCheck ())
279+ }
285280
286281 apiClient , err := client .ClientFromCfg (hostname , cfg )
287282 if err != nil {
0 commit comments