diff --git a/completers/tofu_completer/cmd/action/resource.go b/completers/tofu_completer/cmd/action/resource.go new file mode 100644 index 0000000000..8e10d37c80 --- /dev/null +++ b/completers/tofu_completer/cmd/action/resource.go @@ -0,0 +1,16 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/terraform" + "github.com/spf13/cobra" +) + +func ActionResources(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if f := cmd.Flag("state"); f != nil { + return terraform.ActionResources(f.Value.String()) + } + return terraform.ActionResources("") + }) +} diff --git a/completers/tofu_completer/cmd/apply.go b/completers/tofu_completer/cmd/apply.go new file mode 100644 index 0000000000..1df165469d --- /dev/null +++ b/completers/tofu_completer/cmd/apply.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var applyCmd = &cobra.Command{ + Use: "apply [options] [PLAN]", + Short: "Create or update infrastructure", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(applyCmd).Standalone() + + applyCmd.Flags().BoolS("auto-approve", "auto-approve", false, "Skip interactive approval of plan before applying") + applyCmd.Flags().StringS("backup", "backup", "", "Path to backup the existing state file before modifying") + applyCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Show wanings in a more compact form that includes only the summary messages") + applyCmd.Flags().BoolS("destroy", "destroy", false, "Destroy Terraform-managed infrastructure") + applyCmd.Flags().BoolS("input", "input", false, "Ask for input for variables if not directly set") + applyCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation dangerous if others might concurrently run commands against the same workspace.") + applyCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock") + applyCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color") + applyCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of parallel resource operations") + applyCmd.Flags().StringS("state", "state", "", "Path to read and save state") + applyCmd.Flags().StringS("state-out", "state-out", "", "Path to write state to that is different than \"-state\"") + rootCmd.AddCommand(applyCmd) + + applyCmd.Flag("backup").NoOptDefVal = " " + applyCmd.Flag("lock-timeout").NoOptDefVal = " " + applyCmd.Flag("parallelism").NoOptDefVal = " " + applyCmd.Flag("state").NoOptDefVal = " " + applyCmd.Flag("state-out").NoOptDefVal = " " + + carapace.Gen(applyCmd).FlagCompletion(carapace.ActionMap{ + "backup": carapace.ActionFiles(), + "state": carapace.ActionFiles(), + "state-out": carapace.ActionFiles(), + }) + + carapace.Gen(applyCmd).PositionalCompletion( + carapace.ActionFiles(), + ) +} diff --git a/completers/tofu_completer/cmd/console.go b/completers/tofu_completer/cmd/console.go new file mode 100644 index 0000000000..67747b07a6 --- /dev/null +++ b/completers/tofu_completer/cmd/console.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var consoleCmd = &cobra.Command{ + Use: "console [options]", + Short: "Try Terraform expressions at an interactive command prompt", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(consoleCmd).Standalone() + + consoleCmd.Flags().StringS("state", "state", "", "Legacy option for the local backend only") + consoleCmd.Flags().StringArrayS("var", "var", []string{}, "Set a variable in the Terraform configuration") + consoleCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file") + + consoleCmd.Flag("state").NoOptDefVal = " " + consoleCmd.Flag("var-file").NoOptDefVal = " " + + rootCmd.AddCommand(consoleCmd) + + carapace.Gen(consoleCmd).FlagCompletion(carapace.ActionMap{ + "state": carapace.ActionFiles(), + "var-file": carapace.ActionFiles(), + }) +} diff --git a/completers/tofu_completer/cmd/destroy.go b/completers/tofu_completer/cmd/destroy.go new file mode 100644 index 0000000000..30f87ce42e --- /dev/null +++ b/completers/tofu_completer/cmd/destroy.go @@ -0,0 +1,55 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var destroyCmd = &cobra.Command{ + Use: "destroy [options]", + Short: "Destroy previously-created infrastructure", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(destroyCmd).Standalone() + + // TODO copied flags from plan - documentation is insufficient regarding which are actually applicable to destroy as well + + destroyCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Show warnings in a more compact form that includes only the summary messages.") + destroyCmd.Flags().BoolS("destroy", "destroy", false, "Select the \"destroy\" planning mode.") + destroyCmd.Flags().BoolS("detailed-exitcode", "detailed-exitcode", false, "Return detailed exit codes when the command exits.") + destroyCmd.Flags().StringS("input", "input", "", "Ask for input for variables if not directly set.") + destroyCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + destroyCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + destroyCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color.") + destroyCmd.Flags().StringS("out", "out", "", "Write a plan file to the given path.") + destroyCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of concurrent operations.") + destroyCmd.Flags().BoolS("refresh", "refresh", false, "Skip checking for external changes to remote objects while creating the plan.") + destroyCmd.Flags().BoolS("refresh-only", "refresh-only", false, "Select the \"refresh only\" planning mode.") + destroyCmd.Flags().StringS("replace", "replace", "", "Force replacement of a particular resource instance using its resource address.") + destroyCmd.Flags().StringS("state", "state", "", "A legacy option used for the local backend only.") + destroyCmd.Flags().StringS("target", "target", "", "Limit the planning operation to only the given module, resource.") + destroyCmd.Flags().StringS("var", "var", "", "Set a value for one of the input variables in the root module of the configuration.") + destroyCmd.Flags().StringS("var-file", "var-file", "", "Load variable values from the given file.") + rootCmd.AddCommand(destroyCmd) + + destroyCmd.Flag("input").NoOptDefVal = " " + destroyCmd.Flag("lock-timeout").NoOptDefVal = " " + destroyCmd.Flag("out").NoOptDefVal = " " + destroyCmd.Flag("parallelism").NoOptDefVal = " " + destroyCmd.Flag("replace").NoOptDefVal = " " + destroyCmd.Flag("state").NoOptDefVal = " " + destroyCmd.Flag("target").NoOptDefVal = " " + destroyCmd.Flag("var-file").NoOptDefVal = " " + + carapace.Gen(destroyCmd).FlagCompletion(carapace.ActionMap{ + "out": carapace.ActionFiles(), + "replace": action.ActionResources(destroyCmd).MultiParts("."), + "state": carapace.ActionFiles(), + "target": action.ActionResources(destroyCmd).MultiParts("."), + "var-file": carapace.ActionFiles(), + }) +} diff --git a/completers/tofu_completer/cmd/fmt.go b/completers/tofu_completer/cmd/fmt.go new file mode 100644 index 0000000000..1dec972ef6 --- /dev/null +++ b/completers/tofu_completer/cmd/fmt.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var fmtCmd = &cobra.Command{ + Use: "fmt [options] [target...]", + Short: "Reformat your configuration in the standard style", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(fmtCmd).Standalone() + + fmtCmd.Flags().BoolS("check", "check", false, "Check if the input is formatted") + fmtCmd.Flags().BoolS("diff", "diff", false, "Display diffs of formatting changes") + fmtCmd.Flags().BoolS("list", "list", false, "Don't list files whose formatting differs") + fmtCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color") + fmtCmd.Flags().BoolS("recursive", "recursive", false, "Also process files in subdirectories") + fmtCmd.Flags().BoolS("write", "write", false, "Don't write to source files") + rootCmd.AddCommand(fmtCmd) + + carapace.Gen(fmtCmd).PositionalAnyCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/tofu_completer/cmd/forceUnlock.go b/completers/tofu_completer/cmd/forceUnlock.go new file mode 100644 index 0000000000..3e06d21fbb --- /dev/null +++ b/completers/tofu_completer/cmd/forceUnlock.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var forceUnlockCmd = &cobra.Command{ + Use: "force-unlock LOCK_ID", + Short: "Release a stuck lock on the current workspace", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(forceUnlockCmd).Standalone() + + forceUnlockCmd.Flags().BoolS("force", "force", false, "Don't ask for input for unlock confirmation.") + rootCmd.AddCommand(forceUnlockCmd) + + // TODO lock_id positional completion +} diff --git a/completers/tofu_completer/cmd/get.go b/completers/tofu_completer/cmd/get.go new file mode 100644 index 0000000000..418dc8181b --- /dev/null +++ b/completers/tofu_completer/cmd/get.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var getCmd = &cobra.Command{ + Use: "get [options] PATH", + Short: "Install or upgrade remote Terraform modules", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(getCmd).Standalone() + + getCmd.Flags().BoolS("no-color", "no-color", false, "Disable text coloring in the output.") + getCmd.Flags().BoolS("update", "update", false, "Check already-downloaded modules for available updates") + rootCmd.AddCommand(getCmd) + + carapace.Gen(getCmd).PositionalCompletion( + carapace.ActionFiles(), + ) +} diff --git a/completers/tofu_completer/cmd/graph.go b/completers/tofu_completer/cmd/graph.go new file mode 100644 index 0000000000..2e7f12da42 --- /dev/null +++ b/completers/tofu_completer/cmd/graph.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var graphCmd = &cobra.Command{ + Use: "graph [options]", + Short: "Generate a Graphviz graph of the steps in an operation", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(graphCmd).Standalone() + + graphCmd.Flags().BoolS("draw-cycles", "draw-cycles", false, "Highlight any cycles in the graph with colored edges") + graphCmd.Flags().StringS("plan", "plan", "", "Render graph using the specified plan file") + graphCmd.Flags().StringS("type", "type", "", "Type of graph to output") + rootCmd.AddCommand(graphCmd) + + graphCmd.Flag("plan").NoOptDefVal = " " + graphCmd.Flag("type").NoOptDefVal = " " + + carapace.Gen(graphCmd).FlagCompletion(carapace.ActionMap{ + "plan": carapace.ActionFiles(), + "type": carapace.ActionValues("plan", "plan-refresh-only", "plan-destroy", "apply"), + }) +} diff --git a/completers/tofu_completer/cmd/import.go b/completers/tofu_completer/cmd/import.go new file mode 100644 index 0000000000..8714e5b053 --- /dev/null +++ b/completers/tofu_completer/cmd/import.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var importCmd = &cobra.Command{ + Use: "import [options] ADDR ID", + Short: "Associate existing infrastructure with a Terraform resource", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(importCmd).Standalone() + + importCmd.Flags().StringS("config", "config", "", "Path to a directory of Terraform configuration files") + importCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only") + importCmd.Flags().BoolS("input", "input", false, "Disable interactive input prompts") + importCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation") + importCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock") + importCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color") + importCmd.Flags().StringSliceS("var", "var", []string{}, "Set a variable in the Terraform configuration") + importCmd.Flags().StringSliceS("var-file", "var-file", []string{}, "Set variables in the Terraform configuration from a file") + rootCmd.AddCommand(importCmd) + + importCmd.Flag("config").NoOptDefVal = " " + importCmd.Flag("lock-timeout").NoOptDefVal = " " + importCmd.Flag("var-file").NoOptDefVal = " " + + carapace.Gen(importCmd).FlagCompletion(carapace.ActionMap{ + "config": carapace.ActionDirectories(), + "var-file": carapace.ActionFiles(), + }) + + // TODO positional completion +} diff --git a/completers/tofu_completer/cmd/init.go b/completers/tofu_completer/cmd/init.go new file mode 100644 index 0000000000..6a9e042df4 --- /dev/null +++ b/completers/tofu_completer/cmd/init.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var initCmd = &cobra.Command{ + Use: "init [options]", + Short: "Prepare your working directory for other commands", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(initCmd).Standalone() + + initCmd.Flags().BoolS("backend", "backend", false, "Configure the backend for this configuration") + initCmd.Flags().StringSliceS("backend-config", "backend-config", []string{}, "Backend configuration") + initCmd.Flags().BoolS("force-copy", "force-copy", false, "Suppress prompts about copying state data") + initCmd.Flags().StringS("from-module", "from-module", "", "Copy the contents of the given module into the target directory before initialization") + initCmd.Flags().BoolS("get", "get", false, "Download any modules for this configuration") + initCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only") + initCmd.Flags().BoolS("input", "input", false, "Ask for input if necessary") + initCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during backend migration") + initCmd.Flags().StringS("lockfile", "lockfile", "", "Set a dependency lockfile mode") + initCmd.Flags().BoolS("migrate-state", "migrate-state", false, "Reconfigure the backend, and attempt to migrate any existing state") + initCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color") + initCmd.Flags().BoolS("plugin-dir", "plugin-dir", false, "Directory containing plugin binaries") + initCmd.Flags().BoolS("reconfigure", "reconfigure", false, "Reconfigure the backend, ignoring any saved configuration") + initCmd.Flags().BoolS("upgrade", "upgrade", false, "ignore previously-downloaded objects and install the latest version allowed") + rootCmd.AddCommand(initCmd) + + initCmd.Flag("backend-config").NoOptDefVal = " " + initCmd.Flag("from-module").NoOptDefVal = " " + initCmd.Flag("lockfile").NoOptDefVal = " " + + // TODO module completion + carapace.Gen(initCmd).FlagCompletion(carapace.ActionMap{ + "backend-config": carapace.ActionFiles(), + "lockfile": carapace.ActionValues("readonly"), + }) +} diff --git a/completers/tofu_completer/cmd/login.go b/completers/tofu_completer/cmd/login.go new file mode 100644 index 0000000000..15a29acef0 --- /dev/null +++ b/completers/tofu_completer/cmd/login.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/net" + "github.com/spf13/cobra" +) + +var loginCmd = &cobra.Command{ + Use: "login [hostname]", + Short: "Obtain and save credentials for a remote host", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(loginCmd).Standalone() + + rootCmd.AddCommand(loginCmd) + + carapace.Gen(loginCmd).PositionalCompletion( + net.ActionHosts(), + ) +} diff --git a/completers/tofu_completer/cmd/logout.go b/completers/tofu_completer/cmd/logout.go new file mode 100644 index 0000000000..2f3438d2a2 --- /dev/null +++ b/completers/tofu_completer/cmd/logout.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/net" + "github.com/spf13/cobra" +) + +var logoutCmd = &cobra.Command{ + Use: "logout [hostname]", + Short: "Remove locally-stored credentials for a remote host", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(logoutCmd).Standalone() + + rootCmd.AddCommand(logoutCmd) + + carapace.Gen(logoutCmd).PositionalCompletion( + net.ActionHosts(), // TODO complete authorized hosts + ) +} diff --git a/completers/tofu_completer/cmd/metadata.go b/completers/tofu_completer/cmd/metadata.go new file mode 100644 index 0000000000..de0c105049 --- /dev/null +++ b/completers/tofu_completer/cmd/metadata.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var metadataCmd = &cobra.Command{ + Use: "metadata [options] [args]", + Short: "Metadata related commands", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(metadataCmd).Standalone() + + rootCmd.AddCommand(metadataCmd) +} diff --git a/completers/tofu_completer/cmd/metadata_functions.go b/completers/tofu_completer/cmd/metadata_functions.go new file mode 100644 index 0000000000..998525bd75 --- /dev/null +++ b/completers/tofu_completer/cmd/metadata_functions.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var metadata_functionsCmd = &cobra.Command{ + Use: "functions -json", + Short: "Show signatures and descriptions for the available functions", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(metadata_functionsCmd).Standalone() + + metadata_functionsCmd.Flags().BoolS("json", "json", false, "Prints out a json representation of the available function signatures") + metadataCmd.AddCommand(metadata_functionsCmd) +} diff --git a/completers/tofu_completer/cmd/output.go b/completers/tofu_completer/cmd/output.go new file mode 100644 index 0000000000..733dbbf2b9 --- /dev/null +++ b/completers/tofu_completer/cmd/output.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var outputCmd = &cobra.Command{ + Use: "output [options] [NAME]", + Short: "Show output values from your root module", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(outputCmd).Standalone() + + outputCmd.Flags().BoolS("json", "json", false, "Machine readable output will be printed in JSON format") + outputCmd.Flags().BoolS("no-color", "no-color", false, "Output won't contain any color") + outputCmd.Flags().BoolS("raw", "raw", false, "print the raw string directly") + outputCmd.Flags().StringS("state", "state", "", "Path to the state file to read") + rootCmd.AddCommand(outputCmd) + + carapace.Gen(outputCmd).FlagCompletion(carapace.ActionMap{ + "state": carapace.ActionFiles(), + }) + + // TODO name positional completion +} diff --git a/completers/tofu_completer/cmd/plan.go b/completers/tofu_completer/cmd/plan.go new file mode 100644 index 0000000000..bcea51b799 --- /dev/null +++ b/completers/tofu_completer/cmd/plan.go @@ -0,0 +1,56 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var planCmd = &cobra.Command{ + Use: "plan [options]", + Short: "Show changes required by the current configuration", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(planCmd).Standalone() + + planCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Show warnings in a more compact form that includes only the summary messages.") + planCmd.Flags().BoolS("destroy", "destroy", false, "Select the \"destroy\" planning mode.") + planCmd.Flags().BoolS("detailed-exitcode", "detailed-exitcode", false, "Return detailed exit codes when the command exits.") + planCmd.Flags().String("generate-config-out", "", "write HCL configuration for resources to path") + planCmd.Flags().StringS("input", "input", "", "Ask for input for variables if not directly set.") + planCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + planCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + planCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color.") + planCmd.Flags().StringS("out", "out", "", "Write a plan file to the given path.") + planCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of concurrent operations.") + planCmd.Flags().BoolS("refresh", "refresh", false, "Skip checking for external changes to remote objects while creating the plan.") + planCmd.Flags().BoolS("refresh-only", "refresh-only", false, "Select the \"refresh only\" planning mode.") + planCmd.Flags().StringS("replace", "replace", "", "Force replacement of a particular resource instance using its resource address.") + planCmd.Flags().StringS("state", "state", "", "A legacy option used for the local backend only.") + planCmd.Flags().StringS("target", "target", "", "Limit the planning operation to only the given module, resource.") + planCmd.Flags().StringS("var", "var", "", "Set a value for one of the input variables in the root module of the configuration.") + planCmd.Flags().StringS("var-file", "var-file", "", "Load variable values from the given file.") + rootCmd.AddCommand(planCmd) + + planCmd.Flag("generate-config-out").NoOptDefVal = " " + planCmd.Flag("input").NoOptDefVal = " " + planCmd.Flag("lock-timeout").NoOptDefVal = " " + planCmd.Flag("out").NoOptDefVal = " " + planCmd.Flag("parallelism").NoOptDefVal = " " + planCmd.Flag("replace").NoOptDefVal = " " + planCmd.Flag("state").NoOptDefVal = " " + planCmd.Flag("target").NoOptDefVal = " " + planCmd.Flag("var-file").NoOptDefVal = " " + + carapace.Gen(planCmd).FlagCompletion(carapace.ActionMap{ + "generate-config-out": carapace.ActionFiles(), + "out": carapace.ActionFiles(), + "replace": action.ActionResources(planCmd).MultiParts("."), + "state": carapace.ActionFiles(), + "target": action.ActionResources(planCmd).MultiParts("."), + "var-file": carapace.ActionFiles(), + }) +} diff --git a/completers/tofu_completer/cmd/providers.go b/completers/tofu_completer/cmd/providers.go new file mode 100644 index 0000000000..01d75ad986 --- /dev/null +++ b/completers/tofu_completer/cmd/providers.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var providersCmd = &cobra.Command{ + Use: "providers", + Short: "Show the providers required for this configuration", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(providersCmd).Standalone() + + rootCmd.AddCommand(providersCmd) + + carapace.Gen(providersCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/tofu_completer/cmd/providers_lock.go b/completers/tofu_completer/cmd/providers_lock.go new file mode 100644 index 0000000000..683fcdd9a4 --- /dev/null +++ b/completers/tofu_completer/cmd/providers_lock.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var providers_lockCmd = &cobra.Command{ + Use: "lock", + Short: "Write out dependency locks for the configured provide", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(providers_lockCmd).Standalone() + + providers_lockCmd.Flags().StringS("fs-mirror", "fs-mirror", "", "Consult the given filesystem mirror directory") + providers_lockCmd.Flags().StringS("net-mirror", "net-mirror", "", "Consult the given network mirror") + providers_lockCmd.Flags().StringS("platform", "platform", "", "Choose a target platform to request package checksums for") + providersCmd.AddCommand(providers_lockCmd) + + providers_lockCmd.Flag("fs-mirror").NoOptDefVal = " " + providers_lockCmd.Flag("net-mirror").NoOptDefVal = " " + providers_lockCmd.Flag("platform").NoOptDefVal = " " + + carapace.Gen(providers_lockCmd).FlagCompletion(carapace.ActionMap{ + "fs-mirror": carapace.ActionDirectories(), + }) +} diff --git a/completers/tofu_completer/cmd/providers_mirror.go b/completers/tofu_completer/cmd/providers_mirror.go new file mode 100644 index 0000000000..923ca589bd --- /dev/null +++ b/completers/tofu_completer/cmd/providers_mirror.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var providers_mirrorCmd = &cobra.Command{ + Use: "mirror [options] ", + Short: "Save local copies of all required provider plugin", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(providers_mirrorCmd).Standalone() + + providers_mirrorCmd.Flags().StringS("platform", "platform", "", "Choose which target platform to build a mirror for") + providersCmd.AddCommand(providers_mirrorCmd) + + providers_mirrorCmd.Flag("platform").NoOptDefVal = " " + + // TODO platform completion + + carapace.Gen(providers_mirrorCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/tofu_completer/cmd/providers_schema.go b/completers/tofu_completer/cmd/providers_schema.go new file mode 100644 index 0000000000..2e6354fd1b --- /dev/null +++ b/completers/tofu_completer/cmd/providers_schema.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var providers_schemaCmd = &cobra.Command{ + Use: "schema", + Short: "Show schemas for the providers used in the configuration", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(providers_schemaCmd).Standalone() + providers_schemaCmd.Flags().BoolS("json", "json", false, "Prints out a json representation") + + providersCmd.AddCommand(providers_schemaCmd) +} diff --git a/completers/tofu_completer/cmd/refresh.go b/completers/tofu_completer/cmd/refresh.go new file mode 100644 index 0000000000..7b425e9eeb --- /dev/null +++ b/completers/tofu_completer/cmd/refresh.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var refreshCmd = &cobra.Command{ + Use: "refresh [options]", + Short: "Update the state to match remote systems", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(refreshCmd).Standalone() + + refreshCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "show warnings in a more compact form") + refreshCmd.Flags().BoolS("input", "input", false, "Ask for input for variables if not directly set") + refreshCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation") + refreshCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock") + refreshCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color") + refreshCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of parallel resource operations") + refreshCmd.Flags().StringArrayS("target", "target", []string{}, "Resource to target") + refreshCmd.Flags().StringArrayS("var", "var", []string{}, "Set a variable in the Terraform configuration") + refreshCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file") + rootCmd.AddCommand(refreshCmd) + + refreshCmd.Flag("lock-timeout").NoOptDefVal = " " + refreshCmd.Flag("parallelism").NoOptDefVal = " " + refreshCmd.Flag("target").NoOptDefVal = " " + refreshCmd.Flag("var-file").NoOptDefVal = " " + + // TODO complete var + carapace.Gen(refreshCmd).FlagCompletion(carapace.ActionMap{ + "target": action.ActionResources(refreshCmd).MultiParts("."), + "var-file": carapace.ActionFiles(), + }) +} diff --git a/completers/tofu_completer/cmd/root.go b/completers/tofu_completer/cmd/root.go new file mode 100644 index 0000000000..b1ddd585b7 --- /dev/null +++ b/completers/tofu_completer/cmd/root.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +var rootCmd = &cobra.Command{ + Use: "tofu", + Short: "The open source infrastructure as code tool", + Long: "https://opentofu.org/", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + carapace.Gen(rootCmd).Standalone() + + rootCmd.AddGroup( + &cobra.Group{ID: "main", Title: "Main commands"}, + ) + + rootCmd.Flags().StringS("chdir", "chdir", "", "Switch to a different working directory before executing the given subcommand.") + rootCmd.Flags().BoolS("help", "help", false, "Show this help output, or the help for a specified subcommand.") + rootCmd.Flags().BoolS("version", "version", false, "An alias for the \"version\" subcommand.") + + rootCmd.Flag("chdir").NoOptDefVal = "." + + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ + "chdir": carapace.ActionDirectories(), + }) + + carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action { + if f := rootCmd.Flag("chdir"); f.Changed && f != flag { + return action.Chdir(f.Value.String()) + } + return action + }) +} diff --git a/completers/tofu_completer/cmd/show.go b/completers/tofu_completer/cmd/show.go new file mode 100644 index 0000000000..b8cb6af4f8 --- /dev/null +++ b/completers/tofu_completer/cmd/show.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var showCmd = &cobra.Command{ + Use: "show [options] [path]", + Short: "Show the current state or a saved plan", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(showCmd).Standalone() + + showCmd.Flags().BoolS("json", "json", false, "output in a machine-readable form") + showCmd.Flags().BoolS("no-color", "no-color", false, "output without color") + rootCmd.AddCommand(showCmd) + + carapace.Gen(showCmd).PositionalCompletion( + carapace.ActionFiles(), + ) +} diff --git a/completers/tofu_completer/cmd/state.go b/completers/tofu_completer/cmd/state.go new file mode 100644 index 0000000000..c33cf9a192 --- /dev/null +++ b/completers/tofu_completer/cmd/state.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var stateCmd = &cobra.Command{ + Use: "state [options] [args]", + Short: "Advanced state management", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(stateCmd).Standalone() + + rootCmd.AddCommand(stateCmd) +} diff --git a/completers/tofu_completer/cmd/state_list.go b/completers/tofu_completer/cmd/state_list.go new file mode 100644 index 0000000000..99a82c13e3 --- /dev/null +++ b/completers/tofu_completer/cmd/state_list.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var state_listCmd = &cobra.Command{ + Use: "list [options] [address...]", + Short: "List resources in the state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_listCmd).Standalone() + + state_listCmd.Flags().StringS("id", "id", "", "Filters the results by id") + state_listCmd.Flags().StringS("state", "state", "", "Path to a Terraform state file") + stateCmd.AddCommand(state_listCmd) + + // TODO id completion + carapace.Gen(state_listCmd).FlagCompletion(carapace.ActionMap{ + "state": carapace.ActionFiles(), + }) + + carapace.Gen(state_listCmd).PositionalAnyCompletion( + action.ActionResources(state_listCmd).FilterArgs().MultiParts("_"), + ) +} diff --git a/completers/tofu_completer/cmd/state_mv.go b/completers/tofu_completer/cmd/state_mv.go new file mode 100644 index 0000000000..3c05417932 --- /dev/null +++ b/completers/tofu_completer/cmd/state_mv.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var state_mvCmd = &cobra.Command{ + Use: "mv [options] SOURCE DESTINATION", + Short: "Move an item in the state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_mvCmd).Standalone() + + state_mvCmd.Flags().BoolS("dry-run", "dry-run", false, "only print out what would've been moved") + state_mvCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only") + state_mvCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation") + state_mvCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock") + stateCmd.AddCommand(state_mvCmd) + + state_mvCmd.Flag("lock-timeout").NoOptDefVal = " " + + carapace.Gen(state_mvCmd).PositionalCompletion( + action.ActionResources(state_mvCmd).MultiParts("."), + action.ActionResources(state_mvCmd).MultiParts("."), + ) +} diff --git a/completers/tofu_completer/cmd/state_pull.go b/completers/tofu_completer/cmd/state_pull.go new file mode 100644 index 0000000000..0b78bc9869 --- /dev/null +++ b/completers/tofu_completer/cmd/state_pull.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var state_pullCmd = &cobra.Command{ + Use: "pull [options]", + Short: "Pull current state and output to stdout", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_pullCmd).Standalone() + + stateCmd.AddCommand(state_pullCmd) +} diff --git a/completers/tofu_completer/cmd/state_push.go b/completers/tofu_completer/cmd/state_push.go new file mode 100644 index 0000000000..756098ae7a --- /dev/null +++ b/completers/tofu_completer/cmd/state_push.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var state_pushCmd = &cobra.Command{ + Use: "push [options] PATH", + Short: "Update remote state from a local state file", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_pushCmd).Standalone() + + state_pushCmd.Flags().BoolS("force", "force", false, "Write the state even if lineages don't match or the remote serial is higher") + state_pushCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation") + state_pushCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock") + stateCmd.AddCommand(state_pushCmd) + + state_pushCmd.Flag("lock-timeout").NoOptDefVal = " " + + carapace.Gen(state_pushCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/tofu_completer/cmd/state_replaceProvider.go b/completers/tofu_completer/cmd/state_replaceProvider.go new file mode 100644 index 0000000000..0581567581 --- /dev/null +++ b/completers/tofu_completer/cmd/state_replaceProvider.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var state_replaceProviderCmd = &cobra.Command{ + Use: "replace-provider [options] FROM_PROVIDER_FQN TO_PROVIDER_FQN", + Short: "Replace provider in the state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_replaceProviderCmd).Standalone() + + state_replaceProviderCmd.Flags().BoolS("auto-approve", "auto-approve", false, "Skip interactive approval.") + state_replaceProviderCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only.") + state_replaceProviderCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + state_replaceProviderCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + stateCmd.AddCommand(state_replaceProviderCmd) + + state_replaceProviderCmd.Flag("lock-timeout").NoOptDefVal = " " + + // TODO positional completion +} diff --git a/completers/tofu_completer/cmd/state_rm.go b/completers/tofu_completer/cmd/state_rm.go new file mode 100644 index 0000000000..2fef926b34 --- /dev/null +++ b/completers/tofu_completer/cmd/state_rm.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var state_rmCmd = &cobra.Command{ + Use: "rm [options] ADDRESS...", + Short: "Remove instances from the state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_rmCmd).Standalone() + + state_rmCmd.Flags().StringS("backup", "backup", "", "Path where Terraform should write the backup state.") + state_rmCmd.Flags().BoolS("dry-run", "dry-run", false, "Only print out what would've been removed") + state_rmCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "Continue even if remote and local Terraform versions are incompatible.") + state_rmCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + state_rmCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + state_rmCmd.Flags().StringS("state", "state", "", "Path to the state file to update.") + stateCmd.AddCommand(state_rmCmd) + + state_rmCmd.Flag("backup").NoOptDefVal = " " + state_rmCmd.Flag("lock-timeout").NoOptDefVal = " " + state_rmCmd.Flag("state").NoOptDefVal = " " + + carapace.Gen(state_rmCmd).FlagCompletion(carapace.ActionMap{ + "backup": carapace.ActionFiles(), + "state": carapace.ActionFiles(), + }) + + carapace.Gen(state_rmCmd).PositionalAnyCompletion( + action.ActionResources(state_rmCmd).FilterArgs().MultiParts("."), + ) +} diff --git a/completers/tofu_completer/cmd/state_show.go b/completers/tofu_completer/cmd/state_show.go new file mode 100644 index 0000000000..7af74b38a3 --- /dev/null +++ b/completers/tofu_completer/cmd/state_show.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd/action" + "github.com/spf13/cobra" +) + +var state_showCmd = &cobra.Command{ + Use: "show [options] ADDRESS", + Short: "Show a resource in the state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(state_showCmd).Standalone() + state_showCmd.Flags().StringS("state", "state", "", "Path to a Terraform state file") + stateCmd.AddCommand(state_showCmd) + + state_showCmd.Flag("state").NoOptDefVal = " " + + carapace.Gen(state_showCmd).FlagCompletion(carapace.ActionMap{ + "state": carapace.ActionFiles(), + }) + + carapace.Gen(state_showCmd).PositionalCompletion( + action.ActionResources(state_showCmd).MultiParts("."), + ) +} diff --git a/completers/tofu_completer/cmd/taint.go b/completers/tofu_completer/cmd/taint.go new file mode 100644 index 0000000000..f16da9dff4 --- /dev/null +++ b/completers/tofu_completer/cmd/taint.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var taintCmd = &cobra.Command{ + Use: "taint [options]
", + Short: "Mark a resource instance as not fully functional", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(taintCmd).Standalone() + + taintCmd.Flags().BoolS("allow-missing", "allow-missing", false, "succeed even if the resource is missing.") + taintCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only.") + taintCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + taintCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + rootCmd.AddCommand(taintCmd) + + taintCmd.Flag("lock-timeout").NoOptDefVal = " " + + // TODO positional completion +} diff --git a/completers/tofu_completer/cmd/test.go b/completers/tofu_completer/cmd/test.go new file mode 100644 index 0000000000..778ee4f62d --- /dev/null +++ b/completers/tofu_completer/cmd/test.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var testCmd = &cobra.Command{ + Use: "test [options]", + Short: "Experimental support for module integration testing", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(testCmd).Standalone() + + testCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Use a more compact representation for warnings") + testCmd.Flags().StringS("junit-xml", "junit-xml", "", "also write test results to the given file path") + testCmd.Flags().BoolS("no-color", "no-color", false, "Don't include virtual terminal formatting sequences in the output.") + rootCmd.AddCommand(testCmd) + + testCmd.Flag("junit-xml").NoOptDefVal = " " + + carapace.Gen(testCmd).FlagCompletion(carapace.ActionMap{ + "junit-xml": carapace.ActionFiles(), + }) +} diff --git a/completers/tofu_completer/cmd/untaint.go b/completers/tofu_completer/cmd/untaint.go new file mode 100644 index 0000000000..072d22ccd4 --- /dev/null +++ b/completers/tofu_completer/cmd/untaint.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var untaintCmd = &cobra.Command{ + Use: "untaint [options] name", + Short: "Remove the 'tainted' state from a resource instance", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(untaintCmd).Standalone() + + untaintCmd.Flags().BoolS("allow-missing", "allow-missing", false, "succeed even if the resource is missing.") + untaintCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only.") + untaintCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + untaintCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + rootCmd.AddCommand(untaintCmd) + + untaintCmd.Flag("lock-timeout").NoOptDefVal = " " + + // TODO positional completion +} diff --git a/completers/tofu_completer/cmd/validate.go b/completers/tofu_completer/cmd/validate.go new file mode 100644 index 0000000000..d56fed1be3 --- /dev/null +++ b/completers/tofu_completer/cmd/validate.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var validateCmd = &cobra.Command{ + Use: "validate [options]", + Short: "Check whether the configuration is valid", + GroupID: "main", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(validateCmd).Standalone() + + validateCmd.Flags().BoolS("json", "json", false, "Produce output in a machine-readable JSON format.") + validateCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color.") + rootCmd.AddCommand(validateCmd) +} diff --git a/completers/tofu_completer/cmd/version.go b/completers/tofu_completer/cmd/version.go new file mode 100644 index 0000000000..461a892666 --- /dev/null +++ b/completers/tofu_completer/cmd/version.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version [options]", + Short: "Show the current Terraform version", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(versionCmd).Standalone() + + versionCmd.Flags().BoolS("json", "json", false, "Output the version information as a JSON object.") + rootCmd.AddCommand(versionCmd) +} diff --git a/completers/tofu_completer/cmd/workspace.go b/completers/tofu_completer/cmd/workspace.go new file mode 100644 index 0000000000..e5c9309bc1 --- /dev/null +++ b/completers/tofu_completer/cmd/workspace.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var workspaceCmd = &cobra.Command{ + Use: "workspace", + Short: "Workspace management", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspaceCmd).Standalone() + + rootCmd.AddCommand(workspaceCmd) +} diff --git a/completers/tofu_completer/cmd/workspace_delete.go b/completers/tofu_completer/cmd/workspace_delete.go new file mode 100644 index 0000000000..8e6572594a --- /dev/null +++ b/completers/tofu_completer/cmd/workspace_delete.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/tofu" + "github.com/spf13/cobra" +) + +var workspace_deleteCmd = &cobra.Command{ + Use: "delete [OPTIONS] NAME", + Short: "Delete a workspace", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspace_deleteCmd).Standalone() + + workspace_deleteCmd.Flags().BoolS("force", "force", false, "Remove even a non-empty workspace.") + workspace_deleteCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + workspace_deleteCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + workspaceCmd.AddCommand(workspace_deleteCmd) + + workspace_deleteCmd.Flag("lock-timeout").NoOptDefVal = " " + + carapace.Gen(workspace_deleteCmd).PositionalCompletion( + tofu.ActionWorkspaces(), + ) +} diff --git a/completers/tofu_completer/cmd/workspace_list.go b/completers/tofu_completer/cmd/workspace_list.go new file mode 100644 index 0000000000..e03f73da82 --- /dev/null +++ b/completers/tofu_completer/cmd/workspace_list.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var workspace_listCmd = &cobra.Command{ + Use: "list", + Short: "List Workspaces", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspace_listCmd).Standalone() + + workspaceCmd.AddCommand(workspace_listCmd) +} diff --git a/completers/tofu_completer/cmd/workspace_new.go b/completers/tofu_completer/cmd/workspace_new.go new file mode 100644 index 0000000000..2466e2ff33 --- /dev/null +++ b/completers/tofu_completer/cmd/workspace_new.go @@ -0,0 +1,33 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/tofu" + "github.com/spf13/cobra" +) + +var workspace_newCmd = &cobra.Command{ + Use: "new [OPTIONS] NAME", + Short: "Create a new workspace", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspace_newCmd).Standalone() + + workspace_newCmd.Flags().BoolS("lock", "lock", false, "Don't hold a state lock during the operation.") + workspace_newCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.") + workspace_newCmd.Flags().StringS("state", "state", "", "Copy an existing state file into the new workspace.") + workspaceCmd.AddCommand(workspace_newCmd) + + workspace_newCmd.Flag("lock-timeout").NoOptDefVal = " " + workspace_newCmd.Flag("state").NoOptDefVal = " " + + carapace.Gen(workspace_newCmd).FlagCompletion(carapace.ActionMap{ + "state": carapace.ActionFiles(), + }) + + carapace.Gen(workspace_newCmd).PositionalCompletion( + tofu.ActionWorkspaces(), + ) +} diff --git a/completers/tofu_completer/cmd/workspace_select.go b/completers/tofu_completer/cmd/workspace_select.go new file mode 100644 index 0000000000..f77d5b086c --- /dev/null +++ b/completers/tofu_completer/cmd/workspace_select.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/tofu" + "github.com/spf13/cobra" +) + +var workspace_selectCmd = &cobra.Command{ + Use: "select NAME", + Short: "Select a workspace", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspace_selectCmd).Standalone() + + workspace_selectCmd.Flags().BoolS("or-create", "or-create", false, "Create the Terraform workspace if it doesn't exist") + workspaceCmd.AddCommand(workspace_selectCmd) + + carapace.Gen(workspace_selectCmd).PositionalCompletion( + tofu.ActionWorkspaces(), + ) +} diff --git a/completers/tofu_completer/cmd/workspace_show.go b/completers/tofu_completer/cmd/workspace_show.go new file mode 100644 index 0000000000..6f56df4a28 --- /dev/null +++ b/completers/tofu_completer/cmd/workspace_show.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var workspace_showCmd = &cobra.Command{ + Use: "show", + Short: "Show the name of the current workspac", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(workspace_showCmd).Standalone() + + workspaceCmd.AddCommand(workspace_showCmd) +} diff --git a/completers/tofu_completer/main.go b/completers/tofu_completer/main.go new file mode 100644 index 0000000000..5d1737e95d --- /dev/null +++ b/completers/tofu_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/tofu_completer/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/actions/tools/tofu/resources.go b/pkg/actions/tools/tofu/resources.go new file mode 100644 index 0000000000..621a20d9c7 --- /dev/null +++ b/pkg/actions/tools/tofu/resources.go @@ -0,0 +1,21 @@ +package tofu + +import ( + "strings" + + "github.com/rsteube/carapace" +) + +// ActionResources completes resources +func ActionResources(state string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + args := []string{"state", "list"} + if state != "" { + args = append(args, "--state", state) + } + return carapace.ActionExecCommand("tofu", args...)(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + return carapace.ActionValues(lines[:len(lines)-1]...) + }) + }) +} diff --git a/pkg/actions/tools/tofu/workspace.go b/pkg/actions/tools/tofu/workspace.go new file mode 100644 index 0000000000..b78d8a48ac --- /dev/null +++ b/pkg/actions/tools/tofu/workspace.go @@ -0,0 +1,24 @@ +package tofu + +import ( + "regexp" + "strings" + + "github.com/rsteube/carapace" +) + +// ActionWorkspaces completes workspaces +func ActionWorkspaces() carapace.Action { + return carapace.ActionExecCommand("tofu", "workspace", "list")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + r := regexp.MustCompile(`^[* ] (?P.*)$`) + + vals := make([]string, 0) + for _, line := range lines { + if r.MatchString(line) { + vals = append(vals, r.FindStringSubmatch(line)[1]) + } + } + return carapace.ActionValues(vals...) + }) +}