Skip to content

Commit

Permalink
readd completions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 28, 2024
1 parent 711d87d commit d4871d4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions completers/terramate_completer/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ func init() {
createCmd.Flags().String("name", "", "Name of the stack, defaults to stack dir base name")
createCmd.Flags().Bool("no-generate", false, "Disable code generation for the newly created stacks")
rootCmd.AddCommand(createCmd)

carapace.Gen(createCmd).FlagCompletion(carapace.ActionMap{
"after": terramate.ActionStacks().UniqueList(","),
"before": terramate.ActionStacks().UniqueList(","),
})

carapace.Gen(createCmd).PositionalCompletion(
carapace.ActionFiles(),
)
}
5 changes: 5 additions & 0 deletions completers/terramate_completer/cmd/experimental_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ func init() {

experimental_cloneCmd.Flags().Bool("skip-child-stacks", false, "Clone ignores child stacks")
experimentalCmd.AddCommand(experimental_cloneCmd)

carapace.Gen(experimental_cloneCmd).PositionalCompletion(
carapace.ActionDirectories(),
carapace.ActionDirectories(),
)
}
4 changes: 4 additions & 0 deletions completers/terramate_completer/cmd/experimental_runGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ func init() {
experimental_runGraphCmd.Flags().StringP("label", "l", "", "Label used in graph nodes (it could be either \"stack.name\" or \"stack.dir\"")
experimental_runGraphCmd.Flags().StringP("outfile", "o", "", "Output .dot file")
experimentalCmd.AddCommand(experimental_runGraphCmd)

carapace.Gen(experimental_runGraphCmd).FlagCompletion(carapace.ActionMap{
"outfile": carapace.ActionFiles(),
})
}
4 changes: 4 additions & 0 deletions completers/terramate_completer/cmd/experimental_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ func init() {
experimental_triggerCmd.Flags().String("experimental-status", "", "Filter by status (Deprecated)")
experimental_triggerCmd.Flags().String("reason", "", "Reason for the stack being triggered")
experimentalCmd.AddCommand(experimental_triggerCmd)

carapace.Gen(experimental_triggerCmd).PositionalCompletion(
terramate.ActionStacks(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ func init() {

experimental_vendor_downloadCmd.Flags().StringP("dir", "d", "", "dir to vendor downloaded project")
experimental_vendorCmd.AddCommand(experimental_vendor_downloadCmd)

carapace.Gen(experimental_vendor_downloadCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
})

// TODO positional completion
}
13 changes: 13 additions & 0 deletions completers/terramate_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
var rootCmd = &cobra.Command{
Use: "terramate",
Short: "A tool for managing terraform stacks",
Long: "https://github.com/mineiros-io/terramate",
Run: func(cmd *cobra.Command, args []string) {},
}

Expand All @@ -34,4 +35,16 @@ func init() {
rootCmd.Flags().StringSlice("tags", []string{}, "Filter stacks by tags. Use \":\" for logical AND and \",\" for logical OR. Example: --tags app:prod filters stacks containing tag \"app\" AND \"prod\". If multiple --tags are provided, an OR expression is created. Example: \"--tags a --tags b\" is the same as \"--tags a,b\"")
rootCmd.Flags().StringSliceP("verbose", "v", []string{}, "Increase verboseness of output")
rootCmd.Flags().Bool("version", false, "Terramate version")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"chdir": carapace.ActionDirectories(),
"git-change-base": git.ActionRefs(git.RefOption{}.Default()),
"log-destination": carapace.ActionValues("stderr", "stdout"),
"log-fmt": carapace.ActionValues("console", "text", "json"),
"log-level": carapace.ActionValues("disabled", "trace", "debug", "info", "warn", "error", "fatal").StyleF(style.ForLogLevel),
})

carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
return action.Chdir(rootCmd.Flag("chdir").Value.String())
})
}
5 changes: 5 additions & 0 deletions completers/terramate_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var runCmd = &cobra.Command{

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

runCmd.Flags().BoolS("X", "X", false, "Disable all safeguards")
runCmd.Flags().Bool("cloud-sync-deployment", false, "Enable synchronization of stack execution with the Terramate Cloud")
Expand All @@ -27,4 +28,8 @@ func init() {
runCmd.Flags().Bool("no-recursive", false, "Do not recurse into child stacks")
runCmd.Flags().Bool("reverse", false, "Reverse the order of execution")
rootCmd.AddCommand(runCmd)

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

0 comments on commit d4871d4

Please sign in to comment.