Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add zsh-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
knakayama committed Apr 3, 2016
1 parent 1502a23 commit f0ac076
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions contrib/zsh-completion/_terraforming
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit f0ac076

Please sign in to comment.