Skip to content

Commit 620a6df

Browse files
CLOUDP-124940: Improve user experience of shell detection (#1298)
* CLOUDP-124940: Improve user experience of shell detection * Fix new line * fix mongosh * make binPath internal * Update internal/cli/atlas/quickstart/quick_start.go Co-authored-by: Melissa Mahoney <[email protected]> * line break Co-authored-by: Melissa Mahoney <[email protected]>
1 parent c8c92e0 commit 620a6df

File tree

14 files changed

+33
-222
lines changed

14 files changed

+33
-222
lines changed

docs/atlascli/command/atlas-config-set.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,4 @@ Examples
8686
$ atlas config set ops_manager_url http://localhost:30700/ -P myProfile
8787
Set Organization ID in the default profile:
8888
$ atlas config set org_id 5dd5aaef7a3e5a6c5bd12de4
89-
Set path for the MongoDB Shell in the default profile:
90-
$ atlas config set mongosh_path /usr/local/bin/mongosh
9189

docs/mongocli/command/mongocli-config-set.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,4 @@ Examples
8686
$ mongocli config set ops_manager_url http://localhost:30700/ -P myProfile
8787
Set Organization ID in the default profile:
8888
$ mongocli config set org_id 5dd5aaef7a3e5a6c5bd12de4
89-
Set path for the MongoDB Shell in the default profile:
90-
$ mongocli config set mongosh_path /usr/local/bin/mongosh
9189

internal/cli/atlas/config/init.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ Enter [?] on any option to get help.
8383
return err
8484
}
8585
opts.SetUpOutput()
86-
opts.SetUpMongoSHPath()
8786

8887
if err := config.Save(); err != nil {
8988
return err

internal/cli/atlas/quickstart/mongoshell_setup.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

internal/cli/atlas/quickstart/prompt.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"fmt"
1919

2020
"github.com/AlecAivazis/survey/v2"
21-
"github.com/mongodb/mongodb-atlas-cli/internal/mongosh"
2221
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
2322
"github.com/mongodb/mongodb-atlas-cli/internal/validate"
2423
)
@@ -89,44 +88,6 @@ func newSampleDataQuestion(clusterName string) survey.Prompt {
8988
}
9089
}
9190

92-
func newMongoShellQuestionAccessDeployment(clusterName string) survey.Prompt {
93-
return &survey.Confirm{
94-
Message: fmt.Sprintf("Do you want to connect to %s with MongoDB Shell?", clusterName),
95-
Help: "MongoDB CLI will use your installed version of MongoDB Shell to access your deployments.",
96-
Default: true,
97-
}
98-
}
99-
100-
func newMongoShellPathQuestion() survey.Prompt {
101-
return &survey.Confirm{
102-
Message: "Do you want to provide the path to your MongoDB Shell binary?",
103-
Help: "MongoDB CLI will store the path in your profile, type ‘mongocli config’ to change it.",
104-
Default: true,
105-
}
106-
}
107-
108-
func newIsMongoShellInstalledQuestion() survey.Prompt {
109-
return &survey.Confirm{
110-
Message: "Do you have a MongoDB Shell version installed on your machine?",
111-
Default: true,
112-
}
113-
}
114-
115-
func newMongoShellPathInput() survey.Prompt {
116-
return &survey.Input{
117-
Message: "Default MongoDB Shell Path",
118-
Help: "MongoDB CLI will use your installed version of MongoDB Shell to access your deployments.",
119-
Default: mongosh.Path(),
120-
}
121-
}
122-
123-
func newMongoShellQuestionOpenBrowser() survey.Prompt {
124-
return &survey.Confirm{
125-
Message: "Do you want to download MongoDB Shell [This will open www.mongodb.com on your browser]?",
126-
Default: true,
127-
}
128-
}
129-
13091
func newClusterCreateConfirm() survey.Prompt {
13192
return &survey.Confirm{
13293
Message: "Are you ready to create your Atlas cluster with the above settings?",

internal/cli/atlas/quickstart/quick_start.go

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"syscall"
2626
"time"
2727

28-
"github.com/AlecAivazis/survey/v2"
2928
"github.com/mongodb/mongodb-atlas-cli/internal/cli"
3029
"github.com/mongodb/mongodb-atlas-cli/internal/cli/auth"
3130
"github.com/mongodb/mongodb-atlas-cli/internal/config"
@@ -44,10 +43,20 @@ import (
4443

4544
//go:generate mockgen -destination=../../../mocks/mock_quick_start.go -package=mocks github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/quickstart Flow
4645

47-
const quickstartTemplate = `
48-
Now you can connect to your Atlas cluster with: mongosh -u %s -p %s %s
46+
const quickstartTemplateMongoshDetected = `
47+
MongoDB Shell detected. Connecting to your Atlas cluster:
48+
$ mongosh -u %s -p %s %s
49+
`
50+
51+
const quickstartTemplateMongoshNotDetected = `
52+
MongoDB Shell not detected. To install, open www.mongodb.com/try/download/shell.
53+
54+
MongoDB Shell (mongosh) is an interactive command line interface to query, update, and manage data in your MongoDB database.
4955
56+
Once you install the MongoDB Shell, connect to your database with:
57+
$ mongosh -u %s -p %s %s
5058
`
59+
5160
const quickstartTemplateCloseHandler = `
5261
Enter 'atlas cluster watch %s' to learn when your cluster is available.
5362
`
@@ -79,7 +88,6 @@ const (
7988
DefaultAtlasTier = "M0"
8089
defaultAtlasGovTier = "M30"
8190
atlasAdmin = "atlasAdmin"
82-
mongoshURL = "https://www.mongodb.com/try/download/shell"
8391
defaultProvider = "AWS"
8492
defaultRegion = "US_EAST_1"
8593
defaultRegionGCP = "US_EAST_4"
@@ -104,8 +112,6 @@ type Opts struct {
104112
SampleDataJobID string
105113
SkipSampleData bool
106114
SkipMongosh bool
107-
runMongoShell bool
108-
mongoShellInstalled bool
109115
defaultValue bool
110116
Confirm bool
111117
CurrentIP bool
@@ -264,33 +270,32 @@ func (opts *Opts) Run() error {
264270
return er
265271
}
266272

267-
fmt.Print("Cluster created.")
273+
fmt.Println("Cluster created.")
268274

269-
if err := opts.loadSampleData(); err != nil {
275+
// Get cluster's connection string
276+
cluster, err := opts.store.AtlasCluster(opts.ConfigProjectID(), opts.ClusterName)
277+
if err != nil {
270278
return err
271279
}
272280

273-
if err := opts.askMongoShellQuestion(); err != nil {
281+
fmt.Printf("Your connection string: %v\n", cluster.ConnectionStrings.StandardSrv)
282+
283+
if err := opts.loadSampleData(); err != nil {
274284
return err
275285
}
276286

277-
// If user does not want to open MongoShell, skip everything below
278-
if !opts.runMongoShell {
287+
if opts.SkipMongosh {
279288
return nil
280289
}
281-
// Get cluster's connection string
282-
cluster, err := opts.store.AtlasCluster(opts.ConfigProjectID(), opts.ClusterName)
283-
if err != nil {
284-
return err
285-
}
286290

287-
fmt.Printf(quickstartTemplate, opts.DBUsername, opts.DBUserPassword, cluster.ConnectionStrings.StandardSrv)
291+
if !mongosh.Detect() {
292+
fmt.Printf(quickstartTemplateMongoshNotDetected, opts.DBUsername, opts.DBUserPassword, cluster.ConnectionStrings.StandardSrv)
288293

289-
if opts.runMongoShell && config.MongoShellPath() != "" {
290-
return mongosh.Run(config.MongoShellPath(), opts.DBUsername, opts.DBUserPassword, cluster.ConnectionStrings.StandardSrv)
294+
return nil
291295
}
292296

293-
return nil
297+
fmt.Printf(quickstartTemplateMongoshDetected, opts.DBUsername, opts.DBUserPassword, cluster.ConnectionStrings.StandardSrv)
298+
return mongosh.Run(opts.DBUsername, opts.DBUserPassword, cluster.ConnectionStrings.StandardSrv)
294299
}
295300

296301
func (opts *Opts) createResources() error {
@@ -365,17 +370,6 @@ func (opts *Opts) askSampleDataQuestion() error {
365370
return nil
366371
}
367372

368-
func askMongoShellAndSetConfig() error {
369-
var mongoShellPath string
370-
q := newMongoShellPathInput()
371-
if err := telemetry.TrackAskOne(q, &mongoShellPath, survey.WithValidator(validate.Path)); err != nil {
372-
return err
373-
}
374-
375-
config.SetMongoShellPath(mongoShellPath)
376-
return config.Save()
377-
}
378-
379373
// setupCloseHandler creates a 'listener' on a new goroutine which will notify the
380374
// program if it receives an interrupt from the OS. We then handle this by printing
381375
// the dbUsername and dbPassword.

internal/cli/atlas/quickstart/quick_start_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ func TestQuickstartOpts_Run(t *testing.T) {
7575
Confirm: true,
7676
}
7777

78-
opts.runMongoShell = true
79-
8078
projectIPAccessList := opts.newProjectIPAccessList()
8179

8280
mockStore.
@@ -124,7 +122,6 @@ func TestQuickstartOpts_Run_NotLoggedIn(t *testing.T) {
124122
Confirm: true,
125123
}
126124

127-
opts.runMongoShell = true
128125
require.Error(t, validate.ErrMissingCredentials, opts.quickstartPreRun(ctx, buf))
129126
}
130127

@@ -164,7 +161,6 @@ func TestQuickstartOpts_Run_NeedLogin_ForceAfterLogin(t *testing.T) {
164161
loginOpts: auth.NewLoginOpts(),
165162
}
166163

167-
opts.runMongoShell = true
168164
setConfig()
169165
projectIPAccessList := opts.newProjectIPAccessList()
170166

@@ -240,8 +236,6 @@ func TestQuickstartOpts_Run_CheckFlagsSet(t *testing.T) {
240236
Confirm: true,
241237
}
242238

243-
opts.runMongoShell = true
244-
245239
projectIPAccessList := opts.newProjectIPAccessList()
246240

247241
mockStore.

internal/cli/auth/login.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ func (opts *LoginOpts) setUpProfile(ctx context.Context) error {
206206
_, _ = fmt.Fprintf(opts.OutWriter, "You can use [%s config set] to change these settings at a later time.\n", config.BinName())
207207
}
208208

209-
opts.SetUpMongoSHPath()
210209
return opts.config.Save()
211210
}
212211

internal/cli/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Enter [?] on any option to get help.
7171
return err
7272
}
7373
opts.SetUpOutput()
74-
opts.SetUpMongoSHPath()
7574

7675
if err := config.Save(); err != nil {
7776
return err

internal/cli/config/set.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ Available properties include: %v.`, config.Properties()),
8080
Set Ops Manager Base URL in the profile myProfile:
8181
$ %[1]s config set ops_manager_url http://localhost:30700/ -P myProfile
8282
Set Organization ID in the default profile:
83-
$ %[1]s config set org_id 5dd5aaef7a3e5a6c5bd12de4
84-
Set path for the MongoDB Shell in the default profile:
85-
$ %[1]s config set mongosh_path /usr/local/bin/mongosh`, config.BinName()),
83+
$ %[1]s config set org_id 5dd5aaef7a3e5a6c5bd12de4`, config.BinName()),
8684
Annotations: map[string]string{
8785
"args": "propertyName,value",
8886
"requiredArgs": "propertyName,value",

0 commit comments

Comments
 (0)