From f0ac0762159cc9d36e7729afc543ede418b61743 Mon Sep 17 00:00:00 2001 From: knakayama Date: Tue, 15 Mar 2016 01:49:06 +0900 Subject: [PATCH] Add zsh-completion --- contrib/zsh-completion/_terraforming | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 contrib/zsh-completion/_terraforming diff --git a/contrib/zsh-completion/_terraforming b/contrib/zsh-completion/_terraforming new file mode 100644 index 00000000..b50ea0a7 --- /dev/null +++ b/contrib/zsh-completion/_terraforming @@ -0,0 +1,65 @@ +#compdef terraforming + +function _terraforming() { + local context curcontext=$curcontext state line + typeset -A opt_args + local ret=1 + + _arguments -C \ + '1: :__terraforming_sub_commands' \ + '*:: :->args' \ + && ret=0 + + case $state in + (args) + case $words[1] in + (help) + _arguments -C \ + '1: :__terraforming_sub_commands' \ + '(-)*:: :->null_state' \ + && ret=0 + ;; + (*) + _arguments -C \ + '--merge=[(TFSTATE) tfstate file to merge]:tfstate file to merge:_files' \ + '--overwrite[Overwrite existing tfstate]' \ + '--no-overwrite[Do not overwrite existing tfstate]' \ + '--tfstate[Generate tfstate]' \ + '--no-tfstate[Do not generate tfstate]' \ + '--profile[(PROFILE) AWS credentials profile]:AWS credentials profile:__profiles' \ + && ret=0 + ;; + esac + ;; + esac + + return ret +} + +__terraforming_sub_commands() { + local -a _c + + _c=( + "${(@f)$(terraforming --help \ + | grep ' terraforming' \ + | sed -E 's/^ terraforming //g' \ + | sed -E 's/ *(\[COMMAND\])? *# /:/g')}" + ) + + _describe -t commands terraforming_sub_commands _c +} + +__profiles() { + local _profile_path="${HOME}/.aws/credentials" + local -a _profiles + + _profiles=( + ${(@f)"$(_call_program profiles \ + "grep -E '^\[.*\]$' "$_profile_path" \ + | sed -e 's/\[//' -e 's/\]//'")"} + ) + + _describe -t profiles Profiles _profiles +} + +_terraforming "$@"