command: parameter autocomplete for "terraform workspace ..."

Shell tab completion for all of the subcommands under
"terraform workspace", providing the appropriate kind of auto-complete for
each argument, along with completion for for any flags.
This commit is contained in:
Martin Atkins 2017-09-25 19:02:12 -07:00
parent 793da43a72
commit ece06c35b8
5 changed files with 64 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/command/clistate"
"github.com/hashicorp/terraform/state"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
type WorkspaceDeleteCommand struct {
@ -156,6 +157,21 @@ func (c *WorkspaceDeleteCommand) Run(args []string) int {
return 0
}
func (c *WorkspaceDeleteCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{
complete.PredictNothing, // the "select" subcommand itself (already matched)
c.completePredictWorkspaceName(),
complete.PredictDirs(""),
}
}
func (c *WorkspaceDeleteCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{
"-force": complete.PredictNothing,
}
}
func (c *WorkspaceDeleteCommand) Help() string {
helpText := `
Usage: terraform workspace delete [OPTIONS] NAME [DIR]

View File

@ -4,6 +4,8 @@ import (
"bytes"
"fmt"
"strings"
"github.com/posener/complete"
)
type WorkspaceListCommand struct {
@ -75,6 +77,14 @@ func (c *WorkspaceListCommand) Run(args []string) int {
return 0
}
func (c *WorkspaceListCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictDirs("")
}
func (c *WorkspaceListCommand) AutocompleteFlags() complete.Flags {
return nil
}
func (c *WorkspaceListCommand) Help() string {
helpText := `
Usage: terraform workspace list [DIR]

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/state"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
type WorkspaceNewCommand struct {
@ -156,6 +157,20 @@ func (c *WorkspaceNewCommand) Run(args []string) int {
return 0
}
func (c *WorkspaceNewCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{
complete.PredictNothing, // the "new" subcommand itself (already matched)
complete.PredictAnything,
complete.PredictDirs(""),
}
}
func (c *WorkspaceNewCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{
"-state": complete.PredictFiles("*.tfstate"),
}
}
func (c *WorkspaceNewCommand) Help() string {
helpText := `
Usage: terraform workspace new [OPTIONS] NAME [DIR]

View File

@ -5,6 +5,7 @@ import (
"strings"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
type WorkspaceSelectCommand struct {
@ -103,6 +104,18 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
return 0
}
func (c *WorkspaceSelectCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{
complete.PredictNothing, // the "select" subcommand itself (already matched)
c.completePredictWorkspaceName(),
complete.PredictDirs(""),
}
}
func (c *WorkspaceSelectCommand) AutocompleteFlags() complete.Flags {
return nil
}
func (c *WorkspaceSelectCommand) Help() string {
helpText := `
Usage: terraform workspace select NAME [DIR]

View File

@ -2,6 +2,8 @@ package command
import (
"strings"
"github.com/posener/complete"
)
type WorkspaceShowCommand struct {
@ -26,6 +28,14 @@ func (c *WorkspaceShowCommand) Run(args []string) int {
return 0
}
func (c *WorkspaceShowCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *WorkspaceShowCommand) AutocompleteFlags() complete.Flags {
return nil
}
func (c *WorkspaceShowCommand) Help() string {
helpText := `
Usage: terraform workspace show