Last active
July 11, 2017 11:38
-
-
Save knakayama/002e3f5af837df385776 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#compdef apex | |
function _apex() { | |
local context curcontext=$curcontext state line | |
typeset -A opt_args | |
local ret=1 | |
_arguments -C \ | |
'(-C --chdir)'{-C,--chdir}'[<string> Working directory]' \ | |
'(-D --dry-run)'{-D,--dry-run}'[Perform a dry-run]' \ | |
'(-e --env)'{-e,--env}'[<string> Project environment (default "dev")]' \ | |
'(-h --help)'{-h,--help}'[help for apex]' \ | |
'(-l --log-level)'{-l,--log-level}'[<string> Log severity level (default "info")]' \ | |
'(-p --profile)'{-p,--profile}'[<string> AWS profile]: profile:__profiles' \ | |
'(-r --region)'{-r,--region}'[<string> AWS region]' \ | |
'1: :__apex_sub_commands' \ | |
'*:: :->args' \ | |
&& ret=0 | |
case $state in | |
(args) | |
case $words[1] in | |
(delete) | |
_arguments -C \ | |
'(-f --force)'{-f,--force}'[Force deletion]' \ | |
'1: :__apex_functions' \ | |
&& ret=0 | |
;; | |
(deploy) | |
_arguments -C \ | |
'1: :__apex_functions' \ | |
'(-a --alias)'{-a,--alias}'[<string> Function alias (default "current")]' \ | |
'(-c --concurrency)'{-c,--concurrency}'[<int> Concurrent deploys (default 5)]' \ | |
'(-s --set)'{-s,--set}'[<value> Set environment variable (default \[\])]' \ | |
&& ret=0 | |
;; | |
(infra) | |
_arguments -C \ | |
'1: :__apex_infra_sub_commands' \ | |
&& ret=0 | |
;; | |
(invoke) | |
_arguments -C \ | |
'1: :__apex_functions' \ | |
'(-a --alias)'{-a,--alias}'[<string> Function alias (default "current")]' \ | |
'(-L --logs)'{-L,--logs}'[Print logs]' \ | |
&& ret=0 | |
;; | |
(list) | |
_arguments -C \ | |
'--tfvars[Output as Terraform variables]' \ | |
&& ret=0 | |
;; | |
(logs) | |
_arguments -C \ | |
'1: :__apex_functions' \ | |
'(-F --filter)'{-F,--filter}'[<string> Filter logs with pattern]' \ | |
'(-f --follow)'{-f,--follow}'[Follow tails logs for updates]' \ | |
'(-s --start)'{-s,--start}'[<duration> Start time of the search (default 5m0s)]' \ | |
&& ret=0 | |
;; | |
(metrics) | |
_arguments -C \ | |
'1: :__apex_functions' \ | |
'(-s --start)'{-s,--start}'[<duration> Start time of the results (default 24h0m0s)]' \ | |
&& ret=0 | |
;; | |
(rollback) | |
_arguments -C \ | |
'1: :__apex_functions' \ | |
'(-a --alias)'{-a,--alias}'[<string> Function alias (default "current")]' \ | |
'(-v --version)'{-v,--version}'[<string> version to which rollback is done]' \ | |
&& ret=0 | |
;; | |
esac | |
;; | |
esac | |
return ret | |
} | |
__apex_sub_commands() { | |
local -a _c | |
_c=( | |
"${(@f)$(apex --help \ | |
| awk '/Available Commands:/,/^$/' \ | |
| grep -vF 'Available Commands:' \ | |
| grep -vE '^$' \ | |
| sed -E 's/^ *//g' \ | |
| sed -E 's/ +/:/g')}" | |
) | |
_describe -t commands apex_sub_commands _c | |
} | |
__apex_infra_sub_commands() { | |
local -a _c | |
_c=( | |
"${(@f)$(terraform help \ | |
| awk '/Available commands are:/,/^$/' \ | |
| grep -vF 'Available commands are:' \ | |
| grep -vE '^$' \ | |
| sed -E 's/^ *//g' \ | |
| sed -E 's/ +/:/g')}" | |
) | |
_describe -t commands apex_infra_sub_commands _c | |
} | |
__apex_functions() { | |
local -a _functions | |
# perl hack stolen from: | |
# http://stackoverflow.com/questions/7394889/best-way-to-remove-ansi-color-escapes-in-unix | |
_functions=( | |
${(@f)"$(apex list \ | |
| grep -vE '^ |$^' \ | |
| sed -E 's/^ *//g' \ | |
| perl -MTerm::ANSIColor=colorstrip -ne 'print colorstrip($_)')"} | |
) | |
_describe -t commands apex_functions _functions | |
} | |
__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 | |
} | |
_apex "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment