Skip to content

Commit

Permalink
Add shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorsavian committed Jul 10, 2024
1 parent 311b3a5 commit 93328aa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
cmds.NewCertCommand(),
cmds.NewSecretsEncryptCommand(),
cmds.NewTokenCommand(),
cmds.NewCompletionCommand(),
}

if err := app.Run(configfilearg.MustParse(os.Args)); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Test_NewCommands(t *testing.T) {
NewCertCommand(),
NewSecretsEncryptCommand(),
NewTokenCommand(),
NewCompletionCommand(),
}

for _, command := range app.Commands {
Expand Down
18 changes: 18 additions & 0 deletions pkg/cli/cmds/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmds

import (
"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/cli/completion"
"github.com/urfave/cli"
)

var (
k3sCompletionBase = mustCmdFromK3S(cmds.NewCompletionCommand(completion.Run), K3SFlagSet{
"i": copyFlag,
})
)

func NewCompletionCommand() cli.Command {
cmd := k3sCompletionBase
return cmd
}
1 change: 1 addition & 0 deletions pkg/cli/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func validateCloudProviderName(clx *cli.Context, role CLIRole) {
func NewApp() *cli.App {
app := cli.NewApp()
app.Name = appName
app.EnableBashCompletion = true
app.Usage = "Rancher Kubernetes Engine 2"
app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit)
cli.VersionPrinter = func(c *cli.Context) {
Expand Down

0 comments on commit 93328aa

Please sign in to comment.