diff --git a/command/workspace_delete.go b/command/workspace_delete.go index cb96fba5e4..99dac86d3b 100644 --- a/command/workspace_delete.go +++ b/command/workspace_delete.go @@ -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] diff --git a/command/workspace_list.go b/command/workspace_list.go index bd00246eb4..da7f9b19c6 100644 --- a/command/workspace_list.go +++ b/command/workspace_list.go @@ -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] diff --git a/command/workspace_new.go b/command/workspace_new.go index af7ad2265f..71c9fdc1fc 100644 --- a/command/workspace_new.go +++ b/command/workspace_new.go @@ -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] diff --git a/command/workspace_select.go b/command/workspace_select.go index a80c7f68b1..7070cc6116 100644 --- a/command/workspace_select.go +++ b/command/workspace_select.go @@ -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] diff --git a/command/workspace_show.go b/command/workspace_show.go index 0e4d0159b6..cca688d780 100644 --- a/command/workspace_show.go +++ b/command/workspace_show.go @@ -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