Skip to content

Commit

Permalink
Merge pull request #1628 from rsteube/terraform-bool-flags
Browse files Browse the repository at this point in the history
terraform: use bool flags
  • Loading branch information
rsteube authored Apr 2, 2023
2 parents e9aaed4 + fd1425a commit f8b371f
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 133 deletions.
10 changes: 0 additions & 10 deletions completers/terraform_completer/cmd/action/action.go

This file was deleted.

9 changes: 2 additions & 7 deletions completers/terraform_completer/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -20,8 +19,8 @@ func init() {
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().StringS("input", "input", "", "Ask for input for variables if not directly set")
applyCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation dangerous if others might concurrently run commands against the same workspace.")
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")
Expand All @@ -30,17 +29,13 @@ func init() {
rootCmd.AddCommand(applyCmd)

applyCmd.Flag("backup").NoOptDefVal = " "
applyCmd.Flag("input").NoOptDefVal = " "
applyCmd.Flag("lock").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(),
"input": action.ActionBool(),
"lock": action.ActionBool(),
"state": carapace.ActionFiles(),
"state-out": carapace.ActionFiles(),
})
Expand Down
11 changes: 3 additions & 8 deletions completers/terraform_completer/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)
Expand All @@ -23,12 +22,12 @@ func init() {
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().StringS("lock", "lock", "", "Don't hold a state lock during the operation.")
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().StringS("refresh", "refresh", "", "Skip checking for external changes to remote objects while creating the plan.")
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.")
Expand All @@ -38,20 +37,16 @@ func init() {
rootCmd.AddCommand(destroyCmd)

destroyCmd.Flag("input").NoOptDefVal = " "
destroyCmd.Flag("lock").NoOptDefVal = " "
destroyCmd.Flag("lock-timeout").NoOptDefVal = " "
destroyCmd.Flag("out").NoOptDefVal = " "
destroyCmd.Flag("parallelism").NoOptDefVal = " "
destroyCmd.Flag("refresh").NoOptDefVal = " "
destroyCmd.Flag("replace").NoOptDefVal = " "
destroyCmd.Flag("state").NoOptDefVal = " "
destroyCmd.Flag("target").NoOptDefVal = " "
destroyCmd.Flag("var-file").NoOptDefVal = " "

carapace.Gen(destroyCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
"out": carapace.ActionFiles(),
"refresh": action.ActionBool(),
"out": carapace.ActionFiles(),
"replace": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
Expand Down
10 changes: 2 additions & 8 deletions completers/terraform_completer/cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -17,17 +16,12 @@ func init() {

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().StringS("list", "list", "", "Don't list files whose formatting differs")
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().StringS("write", "write", "", "Don't write to source files")
fmtCmd.Flags().BoolS("write", "write", false, "Don't write to source files")
rootCmd.AddCommand(fmtCmd)

carapace.Gen(fmtCmd).FlagCompletion(carapace.ActionMap{
"list": action.ActionBool(),
"write": action.ActionBool(),
})

carapace.Gen(fmtCmd).PositionalCompletion(
carapace.ActionDirectories(),
)
Expand Down
9 changes: 2 additions & 7 deletions completers/terraform_completer/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -17,24 +16,20 @@ func init() {

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().StringS("input", "input", "", "Disable interactive input prompts")
importCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
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("input").NoOptDefVal = " "
importCmd.Flag("lock").NoOptDefVal = " "
importCmd.Flag("lock-timeout").NoOptDefVal = " "
importCmd.Flag("var-file").NoOptDefVal = " "

carapace.Gen(importCmd).FlagCompletion(carapace.ActionMap{
"config": carapace.ActionDirectories(),
"input": action.ActionBool(),
"lock": action.ActionBool(),
"var-file": carapace.ActionFiles(),
})

Expand Down
21 changes: 5 additions & 16 deletions completers/terraform_completer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -16,39 +15,29 @@ var initCmd = &cobra.Command{
func init() {
carapace.Gen(initCmd).Standalone()

initCmd.Flags().StringS("backend", "backend", "", "Configure the backend for this configuration")
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().StringS("get", "get", "", "Download any modules for this configuration")
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().StringS("input", "input", "", "Ask for input if necessary")
initCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during backend migration")
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().StringS("upgrade", "upgrade", "", "ignore previously-downloaded objects and install the latest version allowed")
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("backend").NoOptDefVal = " "
initCmd.Flag("from-module").NoOptDefVal = " "
initCmd.Flag("get").NoOptDefVal = " "
initCmd.Flag("input").NoOptDefVal = " "
initCmd.Flag("lock").NoOptDefVal = " "
initCmd.Flag("lockfile").NoOptDefVal = " "
initCmd.Flag("upgrade").NoOptDefVal = " "

// TODO module completion
carapace.Gen(initCmd).FlagCompletion(carapace.ActionMap{
"backend": action.ActionBool(),
"backend-config": carapace.ActionFiles(),
"get": action.ActionBool(),
"input": action.ActionBool(),
"lock": action.ActionBool(),
"lockfile": carapace.ActionValues("readonly"),
"upgrade": action.ActionBool(),
})
}
11 changes: 3 additions & 8 deletions completers/terraform_completer/cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)
Expand All @@ -21,12 +20,12 @@ func init() {
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().StringS("input", "input", "", "Ask for input for variables if not directly set.")
planCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation.")
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().StringS("refresh", "refresh", "", "Skip checking for external changes to remote objects while creating the plan.")
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.")
Expand All @@ -36,20 +35,16 @@ func init() {
rootCmd.AddCommand(planCmd)

planCmd.Flag("input").NoOptDefVal = " "
planCmd.Flag("lock").NoOptDefVal = " "
planCmd.Flag("lock-timeout").NoOptDefVal = " "
planCmd.Flag("out").NoOptDefVal = " "
planCmd.Flag("parallelism").NoOptDefVal = " "
planCmd.Flag("refresh").NoOptDefVal = " "
planCmd.Flag("replace").NoOptDefVal = " "
planCmd.Flag("state").NoOptDefVal = " "
planCmd.Flag("target").NoOptDefVal = " "
planCmd.Flag("var-file").NoOptDefVal = " "

carapace.Gen(planCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
"out": carapace.ActionFiles(),
"refresh": action.ActionBool(),
"out": carapace.ActionFiles(),
"replace": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
Expand Down
9 changes: 2 additions & 7 deletions completers/terraform_completer/cmd/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)
Expand All @@ -17,8 +16,8 @@ func init() {
carapace.Gen(refreshCmd).Standalone()

refreshCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "show warnings in a more compact form")
refreshCmd.Flags().StringS("input", "input", "", "Ask for input for variables if not directly set")
refreshCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
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")
Expand All @@ -27,17 +26,13 @@ func init() {
refreshCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file")
rootCmd.AddCommand(refreshCmd)

refreshCmd.Flag("input").NoOptDefVal = " "
refreshCmd.Flag("lock").NoOptDefVal = " "
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{
"input": action.ActionBool(),
"lock": action.ActionBool(),
"target": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
Expand Down
8 changes: 1 addition & 7 deletions completers/terraform_completer/cmd/state_mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -17,16 +16,11 @@ func init() {

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().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
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").NoOptDefVal = " "
state_mvCmd.Flag("lock-timeout").NoOptDefVal = " "

carapace.Gen(state_mvCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
})

// TODO positional completion
}
8 changes: 1 addition & 7 deletions completers/terraform_completer/cmd/state_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -16,17 +15,12 @@ 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().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
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").NoOptDefVal = " "
state_pushCmd.Flag("lock-timeout").NoOptDefVal = " "

carapace.Gen(state_pushCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
})

carapace.Gen(state_pushCmd).PositionalCompletion(
carapace.ActionDirectories(),
)
Expand Down
9 changes: 1 addition & 8 deletions completers/terraform_completer/cmd/state_replaceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -17,17 +16,11 @@ func init() {

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().StringS("lock", "lock", "", "Don't hold a state lock during the operation.")
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").NoOptDefVal = " "
state_replaceProviderCmd.Flag("lock-timeout").NoOptDefVal = " "

carapace.Gen(state_replaceProviderCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
"lock-timeout": action.ActionBool(),
})

// TODO positional completion
}
5 changes: 1 addition & 4 deletions completers/terraform_completer/cmd/state_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -18,19 +17,17 @@ func init() {
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().StringS("lock", "lock", "", "Don't hold a state lock during the operation.")
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").NoOptDefVal = " "
state_rmCmd.Flag("lock-timeout").NoOptDefVal = " "
state_rmCmd.Flag("state").NoOptDefVal = " "

carapace.Gen(state_rmCmd).FlagCompletion(carapace.ActionMap{
"backup": carapace.ActionFiles(),
"lock": action.ActionBool(),
"state": carapace.ActionFiles(),
})

Expand Down
Loading

0 comments on commit f8b371f

Please sign in to comment.