This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
forked from dtan4/terraforming
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |