Skip to content

Commit e62755d

Browse files
authored
CLOUDP-123993: Remove unnecessary mentioning to profiles (#1273)
1 parent 53b9abe commit e62755d

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

internal/cli/auth/login.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ func (opts *LoginOpts) Run(ctx context.Context) error {
154154
return err
155155
}
156156

157-
_, _ = fmt.Fprint(opts.OutWriter, "\nYour profile is now configured.\n")
158157
if config.Name() != config.DefaultProfile {
159158
_, _ = fmt.Fprintf(opts.OutWriter, "To use this profile, you must set the flag [-%s %s] for every command.\n", flag.ProfileShort, config.Name())
160159
}
161-
_, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", config.BinName())
162160

163161
return nil
164162
}
@@ -167,6 +165,12 @@ func (opts *LoginOpts) setUpProfile(ctx context.Context) error {
167165
if err := opts.InitStore(ctx); err != nil {
168166
return err
169167
}
168+
// Initialize the text to be displayed if users are asked to select orgs or projects
169+
opts.OnMultipleOrgsOrProjects = func() {
170+
if !opts.AskedOrgsOrProjects {
171+
_, _ = fmt.Fprintf(opts.OutWriter, "\nYou have multiple organizations or projects, select one to proceed.\n")
172+
}
173+
}
170174

171175
if config.OrgID() == "" || !opts.OrgExists(config.OrgID()) {
172176
if err := opts.AskOrg(); err != nil {
@@ -183,6 +187,12 @@ func (opts *LoginOpts) setUpProfile(ctx context.Context) error {
183187
}
184188
opts.SetUpProject()
185189

190+
// Only make references to profile if user was asked about org or projects
191+
if opts.AskedOrgsOrProjects && opts.ProjectID != "" && opts.OrgID != "" {
192+
_, _ = fmt.Fprint(opts.OutWriter, "\nYour profile is now configured.\n")
193+
_, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", config.BinName())
194+
}
195+
186196
opts.SetUpMongoSHPath()
187197
return opts.config.Save()
188198
}

internal/cli/auth/login_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ Paste the code in the browser when prompted to activate your Atlas CLI. Your cod
153153
154154
To continue, go to http://localhost
155155
Successfully logged in as [email protected].
156-
157-
Your profile is now configured.
158-
You can use [mongocli config set] to change these settings at a later time.
159156
`, buf.String())
160157
}
161158

internal/cli/default_setter_opts.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ type ProjectOrgsLister interface {
4242
}
4343

4444
type DefaultSetterOpts struct {
45-
Service string
46-
OpsManagerURL string
47-
ProjectID string
48-
OrgID string
49-
MongoShellPath string
50-
TelemetryEnabled bool
51-
Output string
52-
Store ProjectOrgsLister
53-
OutWriter io.Writer
45+
Service string
46+
OpsManagerURL string
47+
ProjectID string
48+
OrgID string
49+
MongoShellPath string
50+
TelemetryEnabled bool
51+
Output string
52+
Store ProjectOrgsLister
53+
OutWriter io.Writer
54+
AskedOrgsOrProjects bool
55+
OnMultipleOrgsOrProjects func()
5456
}
5557

5658
func (opts *DefaultSetterOpts) InitStore(ctx context.Context) error {
@@ -174,6 +176,7 @@ func (opts *DefaultSetterOpts) AskProject() error {
174176
if err2 := telemetry.TrackAskOne(p, &manually); err2 != nil {
175177
return err2
176178
}
179+
opts.AskedOrgsOrProjects = true
177180
if manually {
178181
p := prompt.NewProjectIDInput()
179182
return telemetry.TrackAskOne(p, &opts.ProjectID, survey.WithValidator(validate.OptionalObjectID))
@@ -182,17 +185,17 @@ func (opts *DefaultSetterOpts) AskProject() error {
182185
return nil
183186
}
184187

185-
fmt.Println("projects", pSlice)
186-
187188
if len(pSlice) == 1 {
188189
opts.ProjectID = pMap[pSlice[0]]
189190
} else {
191+
opts.runOnMultipleOrgsOrProjects()
190192
p := prompt.NewProjectSelect(pSlice)
191193
var projectID string
192194
if err := telemetry.TrackAskOne(p, &projectID); err != nil {
193195
return err
194196
}
195197
opts.ProjectID = pMap[projectID]
198+
opts.AskedOrgsOrProjects = true
196199
}
197200

198201
return nil
@@ -230,6 +233,7 @@ func (opts *DefaultSetterOpts) AskOrg() error {
230233
if err2 := telemetry.TrackAskOne(p, &manually); err2 != nil {
231234
return err2
232235
}
236+
opts.AskedOrgsOrProjects = true
233237
if manually {
234238
p := prompt.NewOrgIDInput()
235239
return telemetry.TrackAskOne(p, &opts.OrgID, survey.WithValidator(validate.OptionalObjectID))
@@ -241,12 +245,14 @@ func (opts *DefaultSetterOpts) AskOrg() error {
241245
if len(oSlice) == 1 {
242246
opts.OrgID = oMap[oSlice[0]]
243247
} else {
248+
opts.runOnMultipleOrgsOrProjects()
244249
p := prompt.NewOrgSelect(oSlice)
245250
var orgID string
246251
if err := telemetry.TrackAskOne(p, &orgID); err != nil {
247252
return err
248253
}
249254
opts.OrgID = oMap[orgID]
255+
opts.AskedOrgsOrProjects = true
250256
}
251257

252258
return nil
@@ -322,3 +328,9 @@ func (*DefaultSetterOpts) DefaultQuestions() []*survey.Question {
322328
}
323329
return q
324330
}
331+
332+
func (opts *DefaultSetterOpts) runOnMultipleOrgsOrProjects() {
333+
if opts.OnMultipleOrgsOrProjects != nil {
334+
opts.OnMultipleOrgsOrProjects()
335+
}
336+
}

0 commit comments

Comments
 (0)