diff --git a/main.go b/main.go index 057c3c215c2..6d1d61551ed 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ func main() { cmds.NewCertCommand(), cmds.NewSecretsEncryptCommand(), cmds.NewTokenCommand(), + cmds.NewCompletionCommand(), } if err := app.Run(configfilearg.MustParse(os.Args)); err != nil { diff --git a/pkg/cli/cmds/cmds_test.go b/pkg/cli/cmds/cmds_test.go index 8ec5840e31f..e010ac8ada6 100644 --- a/pkg/cli/cmds/cmds_test.go +++ b/pkg/cli/cmds/cmds_test.go @@ -20,6 +20,7 @@ func Test_NewCommands(t *testing.T) { NewCertCommand(), NewSecretsEncryptCommand(), NewTokenCommand(), + NewCompletionCommand(), } for _, command := range app.Commands { diff --git a/pkg/cli/cmds/completion.go b/pkg/cli/cmds/completion.go new file mode 100644 index 00000000000..939fd2641bf --- /dev/null +++ b/pkg/cli/cmds/completion.go @@ -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 +} diff --git a/pkg/cli/cmds/root.go b/pkg/cli/cmds/root.go index d72c4179feb..69afc4a6c0b 100644 --- a/pkg/cli/cmds/root.go +++ b/pkg/cli/cmds/root.go @@ -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) {