#compdef ncd __debug() { echo "$@" >> /tmp/ncd_debug } __ncd_caching_policy() { local -a oldp oldp=( "${1}"(Nmh+12) ) # 12 hours (( ${#oldp} )) } __ncd_repo_names() { integer ret=1 if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi local cache_name="_ncd_repo_names" if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "listing repo names..." _ncd_repo_names=($(ncd list:repo)) _store_cache ${cache_name#_} ${cache_name} fi _describe -t repos "repo names" _ncd_repo_names \ && ret=0 return ret } __ncd_dc_containers() { integer ret=1 if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi local cache_name="_ncd_dc_containers" if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "reading docker containers..." _ncd_dc_containers=($(ncd list:container)) _store_cache ${cache_name#_} _ncd_dc_containers fi _describe -t containers "docker containers" _ncd_dc_containers \ && ret=0 return ret } __ncd_dc_commands() { integer ret=1 if ! zstyle -t ":completion:${curcontext}:" cache-policy; then zstyle ":completion:${curcontext}:" cache-policy __ncd_caching_policy fi local cache_name="_ncd_dc_commands" if ( [[ ${(P)+cache_name} -eq 0 ]] || _cache_invalid "${cache_name#_}" ) \ && ! _retrieve_cache "${cache_name#_}"; then _message "reading ncd dc commands..." _ncd_dc_commands=(${(f)"$(ncd dc --help | sed '1,/Commands:/d' | sed '/^$/,$d' | sed 's/^ //' | sed 's/^\([^ ]*\) */\1:/g')"}) _store_cache ${cache_name#_} _ncd_dc_commands fi _describe -t commands "${words[2]} commands" _ncd_dc_commands \ && ret=0 return ret } __ncd_arguments() { integer ret=1 case "${words[1]}" in config) _message "Enter config key" && ret=0 ;; ec2_ip) _message "Enter pattern for EC2 name" && ret=0 ;; aws) local curcontext="${curcontext}" state _arguments -C \ '1: :->scope' \ '*:: :->args' \ && ret=0 case "${state}" in scope) _ncd_aws_scopes=() _ncd_aws_scopes+=("login" "apigateway" "codeartifact-auth-token") _describe -t scope "scope" _ncd_aws_scopes \ && ret=0 ;; args) case "${words[1]}" in apigateway) local curcontext="${curcontext}" state _arguments -C \ '1: :->command' \ '*:: :->flags' \ && ret=0 case "${state}" in command) _ncd_aws_apigateway_commands=() _ncd_aws_apigateway_commands+=("get-api-key" "get-usage-plan" "list-usage-plans" "view-usage-plan" "change-usage-plan" "get-usage" "update-usage") _describe -t commands "commands" _ncd_aws_apigateway_commands \ && ret=0 ;; flags) case "${words[1]}" in get-api-key) _arguments \ '--region[AWS region]:region:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; get-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; list-usage-plans) _arguments \ '--region[AWS region]:region:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; view-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; change-usage-plan) _arguments \ '--region[AWS region]:region:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ && ret=0 ;; get-usage) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--start-date[Start date (YYYY-MM-DD)]:start-date:' \ '--end-date[End date (YYYY-MM-DD)]:end-date:' \ '--refresh[Force refresh cache]' \ '--plot[Show usage plot]' \ && ret=0 ;; update-usage) _arguments \ '--region[AWS region]:region:' \ '--usage-plan-id[Usage plan ID]:usage-plan-id:' \ '--key-id[API key ID]:key-id:' \ '--api-key[API key value]:api-key:' \ '--refresh[Force refresh cache]' \ && ret=0 ;; esac ;; esac ;; esac ;; esac ;; es) _ncd_es_commands=() _ncd_es_commands+=("aqs") _describe -t commands "commands" _ncd_es_commands \ && ret=0 ;; dc) local curcontext="${curcontext}" state _arguments -C \ '1: :->command' \ '*: :->argument' \ && ret=0 case "${state}" in command) __ncd_dc_commands && ret=0 ;; argument) _message "Enter arguments for ncd dc ${words[2]}" && ret=0 case "${words[$CURRENT]}" in -*) ;; *) __ncd_dc_containers && ret=0 ;; esac ;; esac ;; git) local curcontext="${curcontext}" state _arguments -C \ '1: :->command' \ && ret=0 case "${state}" in command) _ncd_git_commands=("default-branch" "pr-sync" "prepare-remote" "rebase" "sync") _describe -t commands "commands" _ncd_git_commands \ && ret=0 ;; esac ;; list) _ncd_list_things=("container" "repo" "repo-window") _describe -t things "things" _ncd_list_things \ && ret=0 ;; k8s) _ncd_k8s_commands=() _ncd_k8s_commands+=("add-context" "current-context") _ncd_k8s_commands+=("create-token" "copy-token") _ncd_k8s_commands+=("exec" "logs") _describe -t commands "commands" _ncd_k8s_commands \ && ret=0 ;; py) _ncd_py_commands=("venv-init" "venv-remove" "try-install") _describe -t commands "commands" _ncd_py_commands \ && ret=0 ;; repo) local curcontext="${curcontext}" state _arguments -C \ '1: :->name' \ && ret=0 case "${state}" in name) _ncd_repo_windows=($(ncd list:repo-window)) _describe -t repo_windows "Repo Windows" _ncd_repo_windows \ && ret=0 __ncd_repo_names && ret=0 ;; esac ;; esac return ret } __ncd_commands() { local -a _ncd_commands=() _ncd_commands+=("on" "off") _ncd_commands+=("git" "list") _ncd_commands+=("dc" "repo") _ncd_commands+=("py" "k8s") _ncd_commands+=("es") _ncd_commands+=("aws") _ncd_commands+=("workspace") _describe -t ncd-commands "commands" _ncd_commands } _ncd() { setopt localoptions typesetsilent local context curcontext="${curcontext}" state state_descr line local -A opt_args integer ret=1 _arguments -C \ '1: :->command' \ '*:: :->argument' \ && ret=0 case "${state}" in command) __ncd_commands && ret=0 ;; argument) curcontext="${curcontext%:*}:${words[1]}:" __ncd_arguments && ret=0 ;; esac return ret } _ncd $@