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" "io/ioutil"
"log" "log"
"os" "os"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
@ -134,6 +135,7 @@ func wrappedMain() int {
defer plugin.CleanupClients() defer plugin.CleanupClients()
// Get the command line args. // Get the command line args.
binName := filepath.Base(os.Args[0])
args := os.Args[1:] args := os.Args[1:]
// Build the CLI so far, we do this so we can query the subcommand. // 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. // Rebuild the CLI with any modified args.
log.Printf("[INFO] CLI command args: %#v", args) log.Printf("[INFO] CLI command args: %#v", args)
cliRunner = &cli.CLI{ cliRunner = &cli.CLI{
Name: binName,
Args: args, Args: args,
Commands: Commands, Commands: Commands,
HelpFunc: helpFunc, HelpFunc: helpFunc,
HelpWriter: os.Stdout, HelpWriter: os.Stdout,
Autocomplete: true,
AutocompleteInstall: "install-autocomplete",
AutocompleteUninstall: "uninstall-autocomplete",
} }
// Pass in the overriding plugin paths from config // Pass in the overriding plugin paths from config