diff --git a/completers/docker_completer/cmd/action/action.go b/completers/docker_completer/cmd/action/action.go index 721af0f2bf..bdb9eb95e4 100644 --- a/completers/docker_completer/cmd/action/action.go +++ b/completers/docker_completer/cmd/action/action.go @@ -108,3 +108,14 @@ func ActionDetachKeys() carapace.Action { // "detach-keys": carapace.ActionValues("{a-z}", `ctrl-\`, "ctrl-@", "ctrl-[", "ctrl-]", "ctrl-^", "ctrl-_", "ctrl-{a-z}"), return carapace.ActionValues() } + +func ActionContexts() carapace.Action { + return carapace.ActionCallback(func(args []string) carapace.Action { + if output, err := exec.Command("docker", "context", "ls", "--format", "{{.Name}}\n{{.Description}}").Output(); err != nil { + return carapace.ActionMessage(err.Error()) + } else { + vals := strings.Split(string(output), "\n") + return carapace.ActionValuesDescribed(vals[:len(vals)-1]...) + } + }) +} diff --git a/completers/docker_completer/cmd/context.go b/completers/docker_completer/cmd/context.go new file mode 100644 index 0000000000..d98711ec47 --- /dev/null +++ b/completers/docker_completer/cmd/context.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var contextCmd = &cobra.Command{ + Use: "context", + Short: "Manage contexts", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(contextCmd).Standalone() + + rootCmd.AddCommand(contextCmd) +} diff --git a/completers/docker_completer/cmd/context_create.go b/completers/docker_completer/cmd/context_create.go new file mode 100644 index 0000000000..e7bf25eb28 --- /dev/null +++ b/completers/docker_completer/cmd/context_create.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var context_createCmd = &cobra.Command{ + Use: "create", + Short: "Create a context", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_createCmd).Standalone() + + context_createCmd.Flags().String("default-stack-orchestrator", "", "Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)") + context_createCmd.Flags().String("description", "", "Description of the context") + context_createCmd.Flags().String("docker", "", "set the docker endpoint (default [])") + context_createCmd.Flags().String("from", "", "create context from a named context") + context_createCmd.Flags().String("kubernetes", "", "set the kubernetes endpoint (default [])") + contextCmd.AddCommand(context_createCmd) +} diff --git a/completers/docker_completer/cmd/context_export.go b/completers/docker_completer/cmd/context_export.go new file mode 100644 index 0000000000..4b5822a4d4 --- /dev/null +++ b/completers/docker_completer/cmd/context_export.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_exportCmd = &cobra.Command{ + Use: "export", + Short: "Export a context to a tar or kubeconfig file", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_exportCmd).Standalone() + + context_exportCmd.Flags().Bool("kubeconfig", false, "Export as a kubeconfig file") + contextCmd.AddCommand(context_exportCmd) + + carapace.Gen(context_exportCmd).PositionalCompletion( + action.ActionContexts(), + carapace.ActionFiles(""), + ) +} diff --git a/completers/docker_completer/cmd/context_import.go b/completers/docker_completer/cmd/context_import.go new file mode 100644 index 0000000000..fb1a18824d --- /dev/null +++ b/completers/docker_completer/cmd/context_import.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_importCmd = &cobra.Command{ + Use: "import", + Short: "Import a context from a tar or zip file", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_importCmd).Standalone() + + contextCmd.AddCommand(context_importCmd) + + carapace.Gen(context_importCmd).PositionalCompletion( + action.ActionContexts(), + carapace.ActionFiles(""), + ) +} diff --git a/completers/docker_completer/cmd/context_inspect.go b/completers/docker_completer/cmd/context_inspect.go new file mode 100644 index 0000000000..7843cc73ad --- /dev/null +++ b/completers/docker_completer/cmd/context_inspect.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_inspectCmd = &cobra.Command{ + Use: "inspect", + Short: "Display detailed information on one or more contexts", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_inspectCmd).Standalone() + + context_inspectCmd.Flags().StringP("format", "f", "", "Format the output using the given Go template") + contextCmd.AddCommand(context_inspectCmd) + + carapace.Gen(context_inspectCmd).PositionalAnyCompletion(action.ActionContexts()) +} diff --git a/completers/docker_completer/cmd/context_ls.go b/completers/docker_completer/cmd/context_ls.go new file mode 100644 index 0000000000..ee78d502cc --- /dev/null +++ b/completers/docker_completer/cmd/context_ls.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var context_lsCmd = &cobra.Command{ + Use: "ls", + Short: "List context", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_lsCmd).Standalone() + + context_lsCmd.Flags().String("format", "", "Pretty-print contexts using a Go template") + context_lsCmd.Flags().BoolP("quiet", "q", false, "Only show context names") + contextCmd.AddCommand(context_lsCmd) +} diff --git a/completers/docker_completer/cmd/context_rm.go b/completers/docker_completer/cmd/context_rm.go new file mode 100644 index 0000000000..400e7f7ca1 --- /dev/null +++ b/completers/docker_completer/cmd/context_rm.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_rmCmd = &cobra.Command{ + Use: "rm", + Short: "Remove one or more contexts", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_rmCmd).Standalone() + + context_rmCmd.Flags().BoolP("force", "f", false, "Force the removal of a context in use") + contextCmd.AddCommand(context_rmCmd) + + carapace.Gen(context_rmCmd).PositionalAnyCompletion(action.ActionContexts()) +} diff --git a/completers/docker_completer/cmd/context_update.go b/completers/docker_completer/cmd/context_update.go new file mode 100644 index 0000000000..0909c6868f --- /dev/null +++ b/completers/docker_completer/cmd/context_update.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_updateCmd = &cobra.Command{ + Use: "update", + Short: "Update a context", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_updateCmd).Standalone() + + context_updateCmd.Flags().String("default-stack-orchestrator", "", "Default orchestrator for stack operations to use") + context_updateCmd.Flags().String("description", "", "Description of the context") + context_updateCmd.Flags().String("docker", "", "set the docker endpoint (default [])") + context_updateCmd.Flags().String("kubernetes", "", "set the kubernetes endpoint (default [])") + contextCmd.AddCommand(context_updateCmd) + + carapace.Gen(context_updateCmd).PositionalCompletion( + action.ActionContexts(), + ) +} diff --git a/completers/docker_completer/cmd/context_use.go b/completers/docker_completer/cmd/context_use.go new file mode 100644 index 0000000000..78bbe2ce25 --- /dev/null +++ b/completers/docker_completer/cmd/context_use.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/docker_completer/cmd/action" + "github.com/spf13/cobra" +) + +var context_useCmd = &cobra.Command{ + Use: "use", + Short: "Set the current docker context", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(context_useCmd).Standalone() + + contextCmd.AddCommand(context_useCmd) + + carapace.Gen(context_useCmd).PositionalCompletion( + action.ActionContexts(), + ) +}