Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/cli/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ func (opts *LoginOpts) Run(ctx context.Context) error {
return err
}

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

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

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

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

opts.SetUpMongoSHPath()
return opts.config.Save()
}
Expand Down
3 changes: 0 additions & 3 deletions internal/cli/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ Paste the code in the browser when prompted to activate your Atlas CLI. Your cod

To continue, go to http://localhost
Successfully logged in as test@10gen.com.

Your profile is now configured.
You can use [mongocli config set] to change these settings at a later time.
`, buf.String())
}

Expand Down
34 changes: 23 additions & 11 deletions internal/cli/default_setter_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ type ProjectOrgsLister interface {
}

type DefaultSetterOpts struct {
Service string
OpsManagerURL string
ProjectID string
OrgID string
MongoShellPath string
TelemetryEnabled bool
Output string
Store ProjectOrgsLister
OutWriter io.Writer
Service string
OpsManagerURL string
ProjectID string
OrgID string
MongoShellPath string
TelemetryEnabled bool
Output string
Store ProjectOrgsLister
OutWriter io.Writer
AskedOrgsOrProjects bool
OnMultipleOrgsOrProjects func()
}

func (opts *DefaultSetterOpts) InitStore(ctx context.Context) error {
Expand Down Expand Up @@ -174,6 +176,7 @@ func (opts *DefaultSetterOpts) AskProject() error {
if err2 := telemetry.TrackAskOne(p, &manually); err2 != nil {
return err2
}
opts.AskedOrgsOrProjects = true
if manually {
p := prompt.NewProjectIDInput()
return telemetry.TrackAskOne(p, &opts.ProjectID, survey.WithValidator(validate.OptionalObjectID))
Expand All @@ -182,17 +185,17 @@ func (opts *DefaultSetterOpts) AskProject() error {
return nil
}

fmt.Println("projects", pSlice)

if len(pSlice) == 1 {
opts.ProjectID = pMap[pSlice[0]]
} else {
opts.runOnMultipleOrgsOrProjects()
p := prompt.NewProjectSelect(pSlice)
var projectID string
if err := telemetry.TrackAskOne(p, &projectID); err != nil {
return err
}
opts.ProjectID = pMap[projectID]
opts.AskedOrgsOrProjects = true
}

return nil
Expand Down Expand Up @@ -230,6 +233,7 @@ func (opts *DefaultSetterOpts) AskOrg() error {
if err2 := telemetry.TrackAskOne(p, &manually); err2 != nil {
return err2
}
opts.AskedOrgsOrProjects = true
if manually {
p := prompt.NewOrgIDInput()
return telemetry.TrackAskOne(p, &opts.OrgID, survey.WithValidator(validate.OptionalObjectID))
Expand All @@ -241,12 +245,14 @@ func (opts *DefaultSetterOpts) AskOrg() error {
if len(oSlice) == 1 {
opts.OrgID = oMap[oSlice[0]]
} else {
opts.runOnMultipleOrgsOrProjects()
p := prompt.NewOrgSelect(oSlice)
var orgID string
if err := telemetry.TrackAskOne(p, &orgID); err != nil {
return err
}
opts.OrgID = oMap[orgID]
opts.AskedOrgsOrProjects = true
}

return nil
Expand Down Expand Up @@ -322,3 +328,9 @@ func (*DefaultSetterOpts) DefaultQuestions() []*survey.Question {
}
return q
}

func (opts *DefaultSetterOpts) runOnMultipleOrgsOrProjects() {
if opts.OnMultipleOrgsOrProjects != nil {
opts.OnMultipleOrgsOrProjects()
}
}