Terragrunt: add shell completion

Created on 11 Apr 2019  路  4Comments  路  Source: gruntwork-io/terragrunt

add shell completion for bash, zsh, and probably other shells as well.

enhancement help wanted

Most helpful comment

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

All 4 comments

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
Was this page helpful?
0 / 5 - 0 ratings