Skip to content

Commit 603ec7e

Browse files
CLOUDP-115605: [MongoCLI] Improve config command to accept opsmanager (#1039)
1 parent a3a5145 commit 603ec7e

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

docs/mongocli/command/mongocli-config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@ Examples
7575

7676
To configure the tool to work with Atlas for Government
7777
$ mongocli config --service cloudgov
78+
$ mongocli config --service gov
7879

7980
To configure the tool to work with Cloud Manager
8081
$ mongocli config --service cloud-manager
82+
$ mongocli config --service cloudmanager
83+
$ mongocli config --service cm
8184

8285
To configure the tool to work with Ops Manager
8386
$ mongocli config --service ops-manager
87+
$ mongocli config --service opsmanager
88+
$ mongocli config --service om
8489

8590

8691
Related Commands

internal/cli/config/config.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ Enter [?] on any option to get help.
8585
return nil
8686
}
8787

88+
func (opts *opts) validateService() error {
89+
if opts.Service == config.CloudService {
90+
return nil
91+
}
92+
93+
if opts.Service == "gov" {
94+
opts.Service = config.CloudGovService
95+
return nil
96+
}
97+
98+
if opts.Service == "cloudmanager" || opts.Service == "cm" {
99+
opts.Service = config.CloudManagerService
100+
return nil
101+
}
102+
103+
if opts.Service == "opsmanager" || opts.Service == "om" {
104+
opts.Service = config.OpsManagerService
105+
return nil
106+
}
107+
108+
if opts.Service != config.OpsManagerService && opts.Service != config.CloudManagerService && opts.Service != config.CloudGovService {
109+
return fmt.Errorf("the '%s' service is not supported. Please run 'mongocli config --help' to see the list of available services", opts.Service)
110+
}
111+
112+
return nil
113+
}
114+
88115
func Builder() *cobra.Command {
89116
opt := &opts{}
90117
cmd := &cobra.Command{
@@ -102,16 +129,23 @@ To find out more, see the documentation: https://docs.mongodb.com/mongocli/stabl
102129
103130
To configure the tool to work with Atlas for Government
104131
$ mongocli config --service cloudgov
132+
$ mongocli config --service gov
105133
106134
To configure the tool to work with Cloud Manager
107135
$ mongocli config --service cloud-manager
136+
$ mongocli config --service cloudmanager
137+
$ mongocli config --service cm
108138
109139
To configure the tool to work with Ops Manager
110140
$ mongocli config --service ops-manager
141+
$ mongocli config --service opsmanager
142+
$ mongocli config --service om
111143
`,
112-
PreRun: func(cmd *cobra.Command, args []string) {
144+
PreRunE: func(cmd *cobra.Command, args []string) error {
113145
opt.OutWriter = cmd.OutOrStdout()
146+
return opt.validateService()
114147
},
148+
115149
RunE: func(cmd *cobra.Command, args []string) error {
116150
return opt.Run(cmd.Context())
117151
},

internal/validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func Credentials() error {
106106

107107
configCMD := "config"
108108
if config.BinName() == "atlas" {
109-
configCMD += "init"
109+
configCMD += " init"
110110
}
111111
return fmt.Errorf(
112112
"%w\n\nTo set credentials, run: %s %s",

0 commit comments

Comments
 (0)