Skip to content

Commit 82cbe6f

Browse files
authored
feat: add fig-autocomplete subcommand (#995)
1 parent 2911a9e commit 82cbe6f

File tree

11 files changed

+100
-18
lines changed

11 files changed

+100
-18
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Flags are a way to modify the command, also may be called "options". Flags alway
111111

112112
#### Documentation Requirements
113113

114-
f you are adding a brand new command, or updating a command that has no doc annotations, please define the following doc structures for the command. For more information on all command structs, see [Cobra](https://pkg.go.dev/github.com/spf13/cobra#Command).
114+
If you are adding a brand new command, or updating a command that has no doc annotations, please define the following doc structures for the command. For more information on all command structs, see [Cobra](https://pkg.go.dev/github.com/spf13/cobra#Command).
115115
- Add `Use` - (Required) Shows the command and arguments if applicable. Will show up in 'help' output.
116116
- Add `Short` - (Required) Briefly describes the command. Will show up in 'help' output.
117117
- Add `Example` - (Required) Example of how to use the command. Will show up in 'help' output.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/spf13/viper v1.10.1
2323
github.com/stretchr/testify v1.7.0
2424
github.com/tangzero/inflector v1.0.0
25+
github.com/withfig/autocomplete-tools/packages/cobra v1.1.3
2526
go.mongodb.org/atlas v0.15.0
2627
go.mongodb.org/ops-manager v0.37.0
2728
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
392392
github.com/tangzero/inflector v1.0.0 h1:933dvPwRUUOAl98hyeeXuzFix3HwDt5j+45lleu8oh0=
393393
github.com/tangzero/inflector v1.0.0/go.mod h1:OknKjAyDPCDzcWt0yOh2I7hqTukEdyyApcX3/KOhuXc=
394394
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
395+
github.com/withfig/autocomplete-tools/packages/cobra v1.1.3 h1:toi+jQYY7SG/DRYZxP2U2VkFeCY+6FYLXEr8QR8VXzY=
396+
github.com/withfig/autocomplete-tools/packages/cobra v1.1.3/go.mod h1:RoXh7+7qknOXL65uTzdzE1mPxqcPwS7FLCE9K5GfmKo=
395397
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
396398
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
397399
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2022 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package figautocomplete
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
genFigSpec "github.com/withfig/autocomplete-tools/packages/cobra"
20+
)
21+
22+
const CmdUse = "fig-autocomplete"
23+
24+
func Builder() *cobra.Command {
25+
opts := genFigSpec.Opts{
26+
Use: CmdUse,
27+
}
28+
// command hidden by default
29+
cmd := genFigSpec.NewCmdGenFigSpec(opts)
30+
cmd.Aliases = []string{}
31+
return cmd
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2022 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build unit
16+
// +build unit
17+
18+
package figautocomplete
19+
20+
import (
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
func TestBuilder(t *testing.T) {
27+
got := Builder()
28+
a := assert.New(t)
29+
a.Equal(got.Use, "fig-autocomplete")
30+
a.Len(got.Commands(), 0)
31+
a.True(got.HasAvailableFlags())
32+
}

internal/cli/opsmanager/clusters/unmanage.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ func UnmanageBuilder() *cobra.Command {
7474
DeleteOpts: cli.NewDeleteOpts("", "Cluster not deleted\""),
7575
}
7676
cmd := &cobra.Command{
77-
Use: "unmanage <name>",
78-
Aliases: []string{"rm"},
79-
Short: "Stop managing a cluster via automation.",
80-
Long: "This commands only removes entries from the automation config but does not actually remove a cluster.",
81-
Args: require.ExactArgs(1),
77+
Use: "unmanage <name>",
78+
Short: "Stop managing a cluster via automation.",
79+
Long: "This commands only removes entries from the automation config but does not actually remove a cluster.",
80+
Args: require.ExactArgs(1),
8281
PreRunE: func(cmd *cobra.Command, args []string) error {
8382
if err := opts.PreRunE(opts.ValidateProjectID, opts.initStore(cmd.Context())); err != nil {
8483
return err

internal/cli/performanceadvisor/slowoperationthreshold/slow_operation_threshold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Builder() *cobra.Command {
2222
const use = "slowOperationThreshold"
2323
cmd := &cobra.Command{
2424
Use: use,
25-
Aliases: []string{use, "slowOT", "sot", "slowMS"},
25+
Aliases: []string{"slowOT", "sot", "slowMS"},
2626
Short: "Enable or disable management of the slow operation threshold for your cluster.",
2727
}
2828
cmd.AddCommand(

internal/cli/root/atlas/builder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/mongodb/mongocli/internal/cli/atlas/serverless"
4646
"github.com/mongodb/mongocli/internal/cli/auth"
4747
"github.com/mongodb/mongocli/internal/cli/events"
48+
"github.com/mongodb/mongocli/internal/cli/figautocomplete"
4849
"github.com/mongodb/mongocli/internal/cli/iam/globalaccesslists"
4950
"github.com/mongodb/mongocli/internal/cli/iam/globalapikeys"
5051
"github.com/mongodb/mongocli/internal/cli/iam/organizations"
@@ -87,6 +88,10 @@ func Builder(profile *string) *cobra.Command {
8788
config.SetService(config.CloudService)
8889
}
8990

91+
if cmd.Name() == figautocomplete.CmdUse { // figautocomplete command does not require credentials
92+
return nil
93+
}
94+
9095
if cmd.Name() == "quickstart" { // quickstart has its own check
9196
return nil
9297
}
@@ -158,6 +163,7 @@ func Builder(profile *string) *cobra.Command {
158163
loginCmd,
159164
logoutCmd,
160165
whoCmd,
166+
figautocomplete.Builder(),
161167
)
162168

163169
rootCmd.PersistentFlags().StringVarP(profile, flag.Profile, flag.ProfileShort, "", usage.Profile)

internal/cli/root/atlas/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestBuilder(t *testing.T) {
2727
test.CmdValidator(
2828
t,
2929
Builder(&profile),
30-
34,
30+
35,
3131
[]string{},
3232
)
3333
}

internal/cli/root/mongocli/builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/mongodb/mongocli/internal/cli/auth"
2626
"github.com/mongodb/mongocli/internal/cli/cloudmanager"
2727
cliconfig "github.com/mongodb/mongocli/internal/cli/config"
28+
"github.com/mongodb/mongocli/internal/cli/figautocomplete"
2829
"github.com/mongodb/mongocli/internal/cli/iam"
2930
"github.com/mongodb/mongocli/internal/cli/opsmanager"
3031
"github.com/mongodb/mongocli/internal/config"
@@ -83,6 +84,7 @@ func Builder(profile *string, argsWithoutProg []string) *cobra.Command {
8384
"-h",
8485
"completion",
8586
"__complete",
87+
"fig-autocomplete",
8688
}
8789
if !hasArgs || search.StringInSlice(shouldIncludeAtlas, argsWithoutProg[0]) {
8890
rootCmd.AddCommand(atlas.Builder())
@@ -103,6 +105,7 @@ func Builder(profile *string, argsWithoutProg []string) *cobra.Command {
103105
loginCmd,
104106
logoutCmd,
105107
whoCmd,
108+
figautocomplete.Builder(),
106109
)
107110

108111
rootCmd.PersistentFlags().StringVarP(profile, flag.Profile, flag.ProfileShort, "", usage.Profile)

internal/cli/root/mongocli/builder_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,70 +31,77 @@ func TestBuilder(t *testing.T) {
3131
}{
3232
{
3333
name: "atlas",
34-
want: 9,
34+
want: 10,
3535
args: args{
3636
argsWithoutProg: []string{"atlas"},
3737
},
3838
},
3939
{
4040
name: "ops-manager",
41-
want: 8,
41+
want: 9,
4242
args: args{
4343
argsWithoutProg: []string{"ops-manager"},
4444
},
4545
},
4646
{
4747
name: "cloud-manager",
48-
want: 8,
48+
want: 9,
4949
args: args{
5050
argsWithoutProg: []string{"cloud-manager"},
5151
},
5252
},
5353
{
5454
name: "ops-manager alias",
55-
want: 8,
55+
want: 9,
5656
args: args{
5757
argsWithoutProg: []string{"om"},
5858
},
5959
},
6060
{
6161
name: "cloud-manager alias",
62-
want: 8,
62+
want: 9,
6363
args: args{
6464
argsWithoutProg: []string{"cm"},
6565
},
6666
},
6767
{
6868
name: "iam",
69-
want: 8,
69+
want: 9,
7070
args: args{
7171
argsWithoutProg: []string{"iam"},
7272
},
7373
},
7474
{
7575
name: "empty",
76-
want: 9,
76+
want: 10,
7777
args: args{
7878
argsWithoutProg: []string{},
7979
},
8080
},
8181
{
8282
name: "autocomplete",
83-
want: 9,
83+
want: 10,
8484
args: args{
8585
argsWithoutProg: []string{"__complete"},
8686
},
8787
},
8888
{
8989
name: "completion",
90-
want: 9,
90+
want: 10,
9191
args: args{
9292
argsWithoutProg: []string{"completion"},
9393
},
9494
},
95+
{
96+
name: "fig-autocompletion",
97+
want: 10,
98+
args: args{
99+
argsWithoutProg: []string{},
100+
},
101+
},
95102
{
96103
name: "--version",
97-
want: 9,
104+
want: 10,
98105
args: args{
99106
argsWithoutProg: []string{"completion"},
100107
},

0 commit comments

Comments
 (0)