From cd32d5488bac40fb5ad7254c498e8fc7151b39ee Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Mon, 29 Feb 2016 09:14:38 -0500 Subject: [PATCH 1/2] apex automcompletion first pass --- plugins/apex/_apex | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugins/apex/_apex diff --git a/plugins/apex/_apex b/plugins/apex/_apex new file mode 100644 index 00000000..84a7054b --- /dev/null +++ b/plugins/apex/_apex @@ -0,0 +1,39 @@ +#compdef apex + +__function_list() { + declare -a func_cmd + func_cmd=($(apex list 2>/dev/null)) + if [ -n "$cont_cmd" ] + _describe 'functions' func_cmd +} + +local -a _1st_arguments +_1st_arguments=( + 'deploy:Deploy functions and config' + 'invoke:Invoke functions' + 'delete:Delete functions' + 'rollback:Rollback a function' + 'build:Build a function' + 'list:List functions' + 'metrics:Output function metrics' + 'logs:Output function logs' + 'docs:Output documentation' + 'version:Print version of Apex' + 'upgrade:Ugrade apex to the latest stable release' +) + +_arguments '*:: :->command' + +if (( CURRENT == 1 )); then + _describe -t commands "apex command" _1st_arguments + return +fi + +local -a _command_args +case "$words[1]" in + deploy) + _command_args=( + '(-c|--concurrency)'{-c,--concurrency}'[Concurrent deploys (default 5)]' \ + ) + ;; +esac From 74fa11111837067fc7c4d7fa7b547710157b6d55 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Mon, 29 Feb 2016 19:06:23 -0500 Subject: [PATCH 2/2] apex autocompletion for existing commands --- plugins/apex/_apex | 80 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/plugins/apex/_apex b/plugins/apex/_apex index 84a7054b..cc9ba1b2 100644 --- a/plugins/apex/_apex +++ b/plugins/apex/_apex @@ -2,11 +2,66 @@ __function_list() { declare -a func_cmd - func_cmd=($(apex list 2>/dev/null)) - if [ -n "$cont_cmd" ] + func_cmd=($(apex list 2>/dev/null | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | cut -d' ' -f3)) + if [ -n "$func_cmd" ] _describe 'functions' func_cmd } +__deploy() { + _arguments \ + '(-c|--concurrency)'{-c,--concurrency}'[Concurrent deploys (default 5)]' + __function_list +} + +__invoke() { + _arguments \ + '(-L|--logs)'{-l,--logs}'[Print logs]' + __function_list +} + +__delete() { + _arguments \ + '(-f|--force)'{-f,--force}'[Force deletion]' + __function_list +} + +__rollback() { + if ((CURRENT == 3)); then + return + fi + __function_list +} + +__build() { + if ((CURRENT == 3)); then + return + fi + __function_list +} + +__list() { + _arguments \ + '--tfvars[Output as Terraform variables]' +} + +__metrics() { + _arguments \ + '(-s,--start)'{-s,--start}'[Start time of the results (default 24h0m0s)]' + __function_list +} + +__logs() { + _arguments \ + '(-F,--filter)'{-f,--filter}'[Filter logs with pattern]' \ + '(-f,--follow)'{-f,--filter}'[Follow tail logs for updates]' \ + '(-s,--start)'{-s,--start}'[Start time of the search (default 5m0s)]' + __function_list +} + +__docs() { + _arguments '*:files:_files' +} + local -a _1st_arguments _1st_arguments=( 'deploy:Deploy functions and config' @@ -32,8 +87,21 @@ fi local -a _command_args case "$words[1]" in deploy) - _command_args=( - '(-c|--concurrency)'{-c,--concurrency}'[Concurrent deploys (default 5)]' \ - ) - ;; + __deploy ;; + invoke) + __invoke ;; + delete) + __delete ;; + rollback) + __rollback ;; + build) + __build ;; + list) + __list ;; + metrics) + __metrics ;; + logs) + __logs ;; + docs) + __docs ;; esac