Closed fawaf closed 1 year ago
If switching to spf13/cobra
as CLI is an option I'd be easy to provide the completion out of the box: rootCmd.GenBashCompletion(os.Stdout)
@autero1 is this an option or too big for a change? On the other hand we could also quickly rebuild the structure of the terragrunt
commands and generate the completion. The downside is that is has to be kept in sync with the code.
urfave/cli
supports bash completion, but I think we will need something custom regardless of the underlying CLI library for this to work intuitively because of the way terragrunt
works. E.g if you take a look at how the commands are implemented, we aren't defining them as direct commands in the cli struct. This is because we can't define all the available options for most of the commands, since they are passed through to terraform
.
Additionally, we need to somehow merge the terragrunt
completion with the terraform
completions. Otherwise, you get completion for terragrunt
specific commands like plan-all
, but not for terraform
commands that are not explicitly defined in terragrunt
.
I started the project oh-my-zsh
plugin of terragrunt
. I have complete about zsh completion for terraform
subcommands, options and resources (especially when you type -target
option). But I haven't complete all the options of terragrunt
yet (only complete subcommand).
I know It is not solution for this issue, just I hope it can help to someone who are using oh-my-zsh
. Thanks.
Until this is implemented one can just set up terragrunt to at least complete terraform commands in bash by adding this line to .bashrc
or .bash_aliases
:
complete -C ~/.bin/terraform terragrunt
Of course with the appropriate path to the terraform binary.
It also works fine with aliases:
alias tg='terragrunt'
complete -C ~/.bin/terraform tg
This didn't work for me. I've instead use this brute-force solution
In .bashrc
or .bash_aliases
add this:
complete -W "$(terragrunt | grep -A123 "COMMANDS" | head -n-7 | grep '^ ' | awk '{ print $1 }' | grep -v '*' | xargs)" terragrunt tg
on zsh for both terragrunt and terraform completion
complete -o nospace -C /opt/homebrew/bin/terragrunt -C /opt/homebrew/bin/terraform terragrunt
eg:
alias tg=terragrunt
tg <tab>
❯ tg
apply env graph-dependencies logout providers scaffold test workspace
aws-provider-patch fmt hclfmt metadata push show untaint
catalog force-unlock import output refresh state validate
console get init output-module-groups render-json taint validate-inputs
destroy graph login plan run-all terragrunt-info version
❯ tg run-all <tab>
apply env graph init output refresh taint validate
aws-provider-patch fmt graph-dependencies login plan render-json terragrunt-info validate-inputs
console force-unlock hclfmt logout providers show test version
destroy get import metadata push state untaint workspace
add shell completion for bash, zsh, and probably other shells as well.