From 9b5ae9143aaf5fc4e84d454e030a0ba7b7a6e083 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 25 Sep 2017 17:22:37 -0700 Subject: [PATCH] main: enable basic subcommand autocomplete The CLI package has automatic support for shell autocomplete (bash and zsh, at time of writing) for subcommands, so all we need to do here is just opt into it. Users can install this into their shells by running: terraform -install-autocomplete --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index ca4ec7c62..b088d255e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "runtime" "strings" "sync" @@ -134,6 +135,7 @@ func wrappedMain() int { defer plugin.CleanupClients() // Get the command line args. + binName := filepath.Base(os.Args[0]) args := os.Args[1:] // Build the CLI so far, we do this so we can query the subcommand. @@ -175,10 +177,15 @@ func wrappedMain() int { // Rebuild the CLI with any modified args. log.Printf("[INFO] CLI command args: %#v", args) cliRunner = &cli.CLI{ + Name: binName, Args: args, Commands: Commands, HelpFunc: helpFunc, HelpWriter: os.Stdout, + + Autocomplete: true, + AutocompleteInstall: "install-autocomplete", + AutocompleteUninstall: "uninstall-autocomplete", } // Pass in the overriding plugin paths from config