Skip to content

Commit a73f7ab

Browse files
committed
makes config init alias of auth login
1 parent 5fbb105 commit a73f7ab

File tree

3 files changed

+12
-97
lines changed

3 files changed

+12
-97
lines changed

docs/command/atlas-config-init.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ atlas config init
1212
:depth: 1
1313
:class: singlecol
1414

15-
Configure a profile to store access settings for your MongoDB deployment.
15+
Authenticate with MongoDB Atlas.
1616

1717
Public Preview: The atlas api sub-command, automatically generated from the MongoDB Atlas Admin API, offers full coverage of the Admin API and is currently in Public Preview (please provide feedback at https://feedback.mongodb.com/forums/930808-atlas-cli).
1818
Admin API capabilities have their own release lifecycle, which you can check via the provided API endpoint documentation link.
@@ -45,11 +45,15 @@ Options
4545
* - --gov
4646
-
4747
- false
48-
- Create a default profile for atlas for gov
48+
- Log in to Atlas for Government.
4949
* - -h, --help
5050
-
5151
- false
5252
- help for init
53+
* - --noBrowser
54+
-
55+
- false
56+
- Don't automatically open a browser session.
5357

5458
Inherited Options
5559
-----------------

docs/command/atlas-config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Related Commands
6464
* :ref:`atlas-config-delete` - Delete a profile.
6565
* :ref:`atlas-config-describe` - Return the profile you specify.
6666
* :ref:`atlas-config-edit` - Opens the config file with the default text editor.
67-
* :ref:`atlas-config-init` - Configure a profile to store access settings for your MongoDB deployment.
67+
* :ref:`atlas-config-init` - Authenticate with MongoDB Atlas.
6868
* :ref:`atlas-config-list` - Return a list of available profiles by name.
6969
* :ref:`atlas-config-rename` - Rename a profile.
7070
* :ref:`atlas-config-set` - Configure specific properties of a profile.

internal/cli/config/init.go

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -15,106 +15,17 @@
1515
package config
1616

1717
import (
18-
"context"
19-
"fmt"
20-
21-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
22-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
23-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
24-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
25-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/prompt"
26-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry"
27-
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
18+
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/auth"
2819
"github.com/spf13/cobra"
2920
)
3021

31-
const atlas = "atlas"
32-
33-
type initOpts struct {
34-
cli.DigestConfigOpts
35-
gov bool
36-
}
37-
38-
func (opts *initOpts) SetUpAccess() {
39-
opts.Service = config.CloudService
40-
if opts.gov {
41-
opts.Service = config.CloudGovService
42-
}
43-
44-
opts.SetUpServiceAndKeys()
45-
}
46-
47-
func (opts *initOpts) Run(ctx context.Context) error {
48-
_, _ = fmt.Fprintf(opts.OutWriter, `You are configuring a profile for %s.
49-
50-
All values are optional and you can use environment variables (MONGODB_ATLAS_*) instead.
51-
52-
Enter [?] on any option to get help.
53-
54-
`, atlas)
55-
56-
q := prompt.AccessQuestions()
57-
if err := telemetry.TrackAsk(q, opts); err != nil {
58-
return err
59-
}
60-
opts.SetUpAccess()
61-
62-
if err := opts.InitStore(ctx); err != nil {
63-
return err
64-
}
65-
66-
if config.IsAccessSet() {
67-
if err := opts.AskOrg(); err != nil {
68-
return err
69-
}
70-
if err := opts.AskProject(); err != nil {
71-
return err
72-
}
73-
} else {
74-
q := prompt.TenantQuestions()
75-
if err := telemetry.TrackAsk(q, opts); err != nil {
76-
return err
77-
}
78-
}
79-
opts.SetUpProject()
80-
opts.SetUpOrg()
81-
82-
if err := telemetry.TrackAsk(opts.DefaultQuestions(), opts); err != nil {
83-
return err
84-
}
85-
opts.SetUpOutput()
86-
87-
if err := config.Save(); err != nil {
88-
return err
89-
}
90-
91-
_, _ = fmt.Fprintf(opts.OutWriter, "\nYour profile is now configured.\n")
92-
if config.Name() != config.DefaultProfile {
93-
_, _ = fmt.Fprintf(opts.OutWriter, "To use this profile, you must set the flag [-%s %s] for every command.\n", flag.ProfileShort, config.Name())
94-
}
95-
_, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", atlas)
96-
return nil
97-
}
98-
9922
func InitBuilder() *cobra.Command {
100-
opts := &initOpts{}
101-
cmd := &cobra.Command{
102-
Use: "init",
103-
Short: "Configure a profile to store access settings for your MongoDB deployment.",
104-
Example: ` # To configure the tool to work with Atlas:
23+
cmd := auth.LoginBuilder()
24+
cmd.Use = "init"
25+
cmd.Example = ` # To configure the tool to work with Atlas:
10526
atlas config init
10627
10728
# To configure the tool to work with Atlas for Government:
108-
atlas config init --gov`,
109-
PreRun: func(cmd *cobra.Command, _ []string) {
110-
opts.OutWriter = cmd.OutOrStdout()
111-
},
112-
RunE: func(cmd *cobra.Command, _ []string) error {
113-
return opts.Run(cmd.Context())
114-
},
115-
Args: require.NoArgs,
116-
}
117-
cmd.Flags().BoolVar(&opts.gov, flag.Gov, false, usage.Gov)
118-
29+
atlas config init --gov`
11930
return cmd
12031
}

0 commit comments

Comments
 (0)