Skip to content

Commit

Permalink
extracted ActionSafeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 28, 2024
1 parent 3980660 commit a6cfb0c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
10 changes: 7 additions & 3 deletions completers/terramate_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terramate"
"github.com/rsteube/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -31,12 +32,15 @@ func init() {
rootCmd.AddCommand(runCmd)

carapace.Gen(runCmd).FlagCompletion(carapace.ActionMap{
"cloud-sync-terraform-plan-file": carapace.ActionValues(),
"disable-safeguards": carapace.ActionValues("all", "none", "git", "git-untracked", "git-uncommitted", "outdated-code", "git-out-of-sync").UniqueList(","),
// TODO enable dynamic completion
"cloud-sync-terraform-plan-file": carapace.ActionValues(), // TODO enable dynamic completion
"disable-safeguards": terramate.ActionSafeguards().UniqueList(","),
})

carapace.Gen(runCmd).PositionalAnyCompletion(
bridge.ActionCarapaceBin(),
)

carapace.Gen(runCmd).DashAnyCompletion(
carapace.ActionPositional(runCmd),
)
}
15 changes: 15 additions & 0 deletions completers/terramate_completer/cmd/script_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terramate"
"github.com/rsteube/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
)

Expand All @@ -13,6 +15,7 @@ var script_runCmd = &cobra.Command{

func init() {
carapace.Gen(script_runCmd).Standalone()
script_runCmd.Flags().SetInterspersed(false)

script_runCmd.Flags().BoolS("X", "X", false, "Disable all safeguards")
script_runCmd.Flags().Bool("disable-check-gen-code", false, "Disable outdated generated code check")
Expand All @@ -21,4 +24,16 @@ func init() {
script_runCmd.Flags().Bool("dry-run", false, "Plan the execution but do not execute it")
script_runCmd.Flags().Bool("no-recursive", false, "Do not recurse into child stacks")
scriptCmd.AddCommand(script_runCmd)

carapace.Gen(script_runCmd).FlagCompletion(carapace.ActionMap{
"disable-safeguards": terramate.ActionSafeguards().UniqueList(","),
})

carapace.Gen(script_runCmd).PositionalAnyCompletion(
bridge.ActionCarapaceBin(),
)

carapace.Gen(script_runCmd).DashAnyCompletion(
carapace.ActionPositional(script_runCmd),
)
}
18 changes: 18 additions & 0 deletions pkg/actions/tools/terramate/safeguard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package terramate

import "github.com/rsteube/carapace"

// ActionSafeguards completes safeguards
//
// all (Disable all checks)
// git (Disable all git related checks)
func ActionSafeguards() carapace.Action {
return carapace.ActionValuesDescribed(
"all", "Disable all checks",
"git", "Disable all git related checks",
"git-out-of-sync", "Disable the check for git remote out of sync",
"git-uncommitted", "Disable the check for uncommitted files",
"git-untracked", "Disable the check for untracked files",
"outdated-code", "Disable the check for outdated code",
)
}

0 comments on commit a6cfb0c

Please sign in to comment.