Skip to content

Instantly share code, notes, and snippets.

@knakayama
Last active Jul 11, 2017
Embed
What would you like to do?
#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
_functions=(
${(@f)"$(apex list \
| grep -vE '^ |$^' \
| sed -E 's/^ *//g')"}
)
_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