Skip to content

Commit

Permalink
terraform: complete state resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 2, 2023
1 parent f8b371f commit 13c52bc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion completers/terraform_completer/cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ func init() {

carapace.Gen(graphCmd).FlagCompletion(carapace.ActionMap{
"plan": carapace.ActionFiles(),
"type": carapace.ActionValues("plan", "plan-destroy", "apply", "validate", "input", "refresh"),
"type": carapace.ActionValues("plan", "plan-refresh-only", "plan-destroy", "apply"),
})
}
20 changes: 0 additions & 20 deletions completers/terraform_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cmd

import (
"os"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -20,23 +17,6 @@ func Execute() error {
return rootCmd.Execute()
}

func ActionExecute() carapace.Action { // TODO this still needed / correct? maybe use bridging action
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// TODO don't change os.Args
backup := os.Args
for index, arg := range c.Args {
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") {
c.Args[index] = "-" + arg
}
}
if strings.HasPrefix(c.CallbackValue, "-") && !strings.HasPrefix(c.CallbackValue, "--") {
c.CallbackValue = "-" + c.CallbackValue
}
os.Args = backup
return carapace.ActionExecute(rootCmd).Invoke(c).ToA()
})
}

func init() {
carapace.Gen(rootCmd).Standalone()

Expand Down
6 changes: 5 additions & 1 deletion completers/terraform_completer/cmd/state_mv.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/terraform"
"github.com/spf13/cobra"
)

Expand All @@ -22,5 +23,8 @@ func init() {

state_mvCmd.Flag("lock-timeout").NoOptDefVal = " "

// TODO positional completion
carapace.Gen(state_mvCmd).PositionalCompletion(
terraform.ActionResources(),
terraform.ActionResources(),
)
}
7 changes: 6 additions & 1 deletion completers/terraform_completer/cmd/state_rm.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/terraform"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -31,5 +32,9 @@ func init() {
"state": carapace.ActionFiles(),
})

// TODO positional completion
carapace.Gen(state_rmCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return terraform.ActionResources().Invoke(c).Filter(c.Args).ToA()
}),
)
}
5 changes: 5 additions & 0 deletions completers/terraform_completer/cmd/state_show.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/terraform"
"github.com/spf13/cobra"
)

Expand All @@ -21,4 +22,8 @@ func init() {
carapace.Gen(state_showCmd).FlagCompletion(carapace.ActionMap{
"state": carapace.ActionFiles(),
})

carapace.Gen(state_showCmd).PositionalCompletion(
terraform.ActionResources(),
)
}
4 changes: 2 additions & 2 deletions completers/terragrunt_completer/cmd/runAll.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
terraform "github.com/rsteube/carapace-bin/completers/terraform_completer/cmd"
"github.com/rsteube/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +20,6 @@ func init() {
rootCmd.AddCommand(runAllCmd)

carapace.Gen(runAllCmd).PositionalAnyCompletion(
terraform.ActionExecute(),
bridge.ActionCarapaceBin("terraform"),
)
}

0 comments on commit 13c52bc

Please sign in to comment.