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
This commit is contained in:
Martin Atkins 2017-09-25 17:22:37 -07:00
parent 564f5134e3
commit 9b5ae9143a
1 changed files with 7 additions and 0 deletions

View File

@ -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