diff --git a/internal/cmd/commands.go b/internal/cmd/commands.go index f934d412e2..df5c4d5572 100644 --- a/internal/cmd/commands.go +++ b/internal/cmd/commands.go @@ -256,6 +256,24 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) { Func: "get-token", }, nil }, + "config autocomplete": func() (cli.Command, error) { + return &config.AutocompleteCommand{ + Command: base.NewCommand(ui), + Func: "base", + }, nil + }, + "config autocomplete install": func() (cli.Command, error) { + return &config.AutocompleteCommand{ + Command: base.NewCommand(ui), + Func: "install", + }, nil + }, + "config autocomplete uninstall": func() (cli.Command, error) { + return &config.AutocompleteCommand{ + Command: base.NewCommand(ui), + Func: "uninstall", + }, nil + }, "database": func() (cli.Command, error) { return &database.Command{ diff --git a/internal/cmd/commands/config/autocomplete.go b/internal/cmd/commands/config/autocomplete.go new file mode 100644 index 0000000000..25e41ea022 --- /dev/null +++ b/internal/cmd/commands/config/autocomplete.go @@ -0,0 +1,58 @@ +package config + +import ( + "fmt" + + "github.com/hashicorp/boundary/internal/cmd/base" + "github.com/mitchellh/cli" +) + +var _ cli.Command = (*Command)(nil) + +type AutocompleteCommand struct { + *base.Command + + Func string +} + +func (c *AutocompleteCommand) Synopsis() string { + verb := "Install" + switch c.Func { + case "uninstall": + verb = "Uninstall" + case "base": + verb = "Install or uninstall" + } + + return fmt.Sprintf("%s autocompletion for Boundary's CLI", verb) +} + +func (c *AutocompleteCommand) Help() string { + verb := "installs" + switch c.Func { + case "uninstall": + verb = "uninstalls" + case "base": + verb = "installs or uninstalls" + } + + subcmd := "" + switch c.Func { + case "uninstall": + subcmd = " uninstall" + case "install": + subcmd = " install" + } + return base.WrapForHelpText([]string{ + fmt.Sprintf("Usage: boundary config autocomplete%s [options] [args]", subcmd), + "", + fmt.Sprintf(" This command %s autocompletion support for Boundary's CLI", verb), + }) +} + +func (c *AutocompleteCommand) Run(args []string) int { + if len(args) > 0 { + return cli.RunResultHelp + } + return 0 +} diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 1c6161f8ab..dddef81af8 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -21,6 +21,18 @@ import ( // setupEnv parses args and may replace them and sets some env vars to known // values based on format options func setupEnv(args []string) (retArgs []string, format string, outputCurlString bool) { + // handle the workaround for autocomplete install/uninstall not being exported + if len(args) == 3 && + args[0] == "config" && + args[1] == "autocomplete" { + switch args[2] { + case "install": + return []string{"-autocomplete-install"}, "table", false + case "uninstall": + return []string{"-autocomplete-uninstall"}, "table", false + } + } + var nextArgFormat bool for _, arg := range args {