@@ -75,22 +75,15 @@ type LoginOpts struct {
75
75
RefreshToken string
76
76
IsGov bool
77
77
NoBrowser bool
78
- AuthType string
78
+ authType string
79
79
force bool
80
80
SkipConfig bool
81
81
config LoginConfig
82
82
}
83
83
84
- func (opts * LoginOpts ) validateAuthTypeFlag () error {
85
- if opts .AuthType != "" && opts .AuthType != userAccountAuth && opts .AuthType != apiKeysAuth {
86
- return fmt .Errorf ("the authentication type is invalid: %s" , opts .AuthType )
87
- }
88
- return nil
89
- }
90
-
91
84
func (opts * LoginOpts ) promptAuthType () error {
92
85
if opts .force {
93
- opts .AuthType = userAccountAuth
86
+ opts .authType = userAccountAuth
94
87
return nil
95
88
}
96
89
authTypePrompt := & survey.Select {
@@ -101,24 +94,7 @@ func (opts *LoginOpts) promptAuthType() error {
101
94
return authTypeDescription [value ]
102
95
},
103
96
}
104
- return telemetry .TrackAskOne (authTypePrompt , & opts .AuthType )
105
- }
106
-
107
- func (opts * LoginOpts ) validateAndPrompt () error {
108
- err := opts .validateAuthTypeFlag ()
109
- if err != nil {
110
- return err
111
- }
112
-
113
- // if opts.AuthType is empty, we prompt the user to select an auth type
114
- if opts .AuthType == "" {
115
- err := opts .promptAuthType ()
116
- if err != nil {
117
- return fmt .Errorf ("failed to select authentication type: %w" , err )
118
- }
119
- }
120
-
121
- return nil
97
+ return telemetry .TrackAskOne (authTypePrompt , & opts .authType )
122
98
}
123
99
124
100
func (opts * LoginOpts ) SetUpAccess () {
@@ -259,11 +235,11 @@ func (opts *LoginOpts) runUserAccountLogin(ctx context.Context) error {
259
235
}
260
236
261
237
func (opts * LoginOpts ) LoginRun (ctx context.Context ) error {
262
- if err := opts .validateAndPrompt (); err != nil {
263
- return err
238
+ if err := opts .promptAuthType (); err != nil {
239
+ return fmt . Errorf ( "failed to select authentication type: %w" , err )
264
240
}
265
241
266
- if opts .AuthType == apiKeysAuth {
242
+ if opts .authType == apiKeysAuth {
267
243
return opts .runAPIKeysLogin (ctx )
268
244
}
269
245
@@ -444,14 +420,11 @@ func LoginBuilder() *cobra.Command {
444
420
Args : require .NoArgs ,
445
421
}
446
422
447
- cmd .Flags ().StringVar (& opts .AuthType , "authType" , "" , "Authentication type to use. Valid values are 'UserAccount' and 'APIKeys'." )
448
423
cmd .Flags ().BoolVar (& opts .IsGov , "gov" , false , "Log in to Atlas for Government." )
449
424
cmd .Flags ().BoolVar (& opts .NoBrowser , "noBrowser" , false , "Don't try to open a browser session to authenticate your User Account." )
450
425
cmd .Flags ().BoolVar (& opts .SkipConfig , "skipConfig" , false , "Skip profile configuration." )
451
426
_ = cmd .Flags ().MarkDeprecated ("skipConfig" , "if you configured a profile, the command skips the config step by default." )
452
427
cmd .Flags ().BoolVar (& opts .force , flag .Force , false , usage .Force )
453
428
_ = cmd .Flags ().MarkHidden (flag .Force )
454
- _ = cmd .Flags ().MarkHidden (flag .Debug )
455
-
456
429
return cmd
457
430
}
0 commit comments