B x `0@sddlZddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ydd l mZWnek rddl ZYnXd Zd Zd Zd ZeeedZedZddZddZddZddZddZddZddZddZd d!Zd"d#Z d$d%Z!d&d'Z"dS)(N)Argument) MultiCommand)Option)split_arg_string)Choice)echo)abc=a %(complete_func)s() { local IFS=$' ' COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ COMP_CWORD=$COMP_CWORD \ %(autocomplete_var)s=complete $1 ) ) return 0 } %(complete_func)setup() { local COMPLETION_OPTIONS="" local BASH_VERSION_ARR=(${BASH_VERSION//./ }) # Only BASH version 4.4 and later have the nosort option. if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then COMPLETION_OPTIONS="-o nosort" fi complete $COMPLETION_OPTIONS -F %(complete_func)s %(script_names)s } %(complete_func)setup a #compdef %(script_names)s %(complete_func)s() { local -a completions local -a completions_with_descriptions local -a response (( ! $+commands[%(script_names)s] )) && return 1 response=("${(@f)$( env COMP_WORDS="${words[*]}" \ COMP_CWORD=$((CURRENT-1)) \ %(autocomplete_var)s="complete_zsh" \ %(script_names)s )}") for key descr in ${(kv)response}; do if [[ "$descr" == "_" ]]; then completions+=("$key") else completions_with_descriptions+=("$key":"$descr") fi done if [ -n "$completions_with_descriptions" ]; then _describe -V unsorted completions_with_descriptions -U fi if [ -n "$completions" ]; then compadd -U -V unsorted -a completions fi compstate[insert]="automenu" } compdef %(complete_func)s %(script_names)s zcomplete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)")bashzshfishz [^a-zA-Z0-9_]cCs>td|dd}t|t}|d|||ddS)N-_z_{}_completion)Z complete_funcZ script_namesZautocomplete_var;)_invalid_ident_char_resubreplace_completion_scriptsgetCOMPLETION_SCRIPT_BASHformatstrip) prog_name complete_varshellZcf_namescriptr7/tmp/pip-unpacked-wheel-za9e8r29/click/_bashcomplete.pyget_completion_script_s  r cCs|j||dd}|j|j}x|rt|jtr|jjsv|j||\}}}|dkrV|S|j|||dd}|j|j}qxD|r|j||\}}}|dkr|S|j|||dddd}|j}qxW|}|j|j}qPqW|S)aParse into a hierarchy of contexts. Contexts are connected through the parent variable. :param cli: command definition :param prog_name: the program that is running :param args: full list of args :return: the final context/command parsed T)resilient_parsingN)parentr!F)r"Zallow_extra_argsallow_interspersed_argsr!)Z make_contextprotected_argsargs isinstancecommandrchainZresolve_command)clirr%ctxcmd_namecmdZsub_ctxrrr resolve_ctxls6    r-cCs|o|dddkS)z :param param_str: param_str to check :return: whether or not this is the start of an option declaration (i.e. starts "-" or "--") Nrrr)Z param_strrrrstart_of_optionsr.cCsrt|tsdS|jrdSd}x>ttdd|DD]$\}}|d|jkrLPt|r4|}q4W|rn||jkrndSdS)aU :param all_args: the full original list of args supplied :param cmd_param: the current command paramter :return: whether or not the last option declaration (i.e. starts "-" or "--") is incomplete and corresponds to this cmd_param. In other words whether this cmd_param option can still accept values FNcSsg|]}|tkr|qSr) WORDBREAK).0argrrr sz(is_incomplete_option..rT)r&rZis_flag enumeratereversednargsr.opts)all_args cmd_paramZ last_optionindexZarg_strrrris_incomplete_options r:cCs^t|tsdS||j}|dkr$dS|jdkr2dSt|tjrZ|jdkrZt||jkrZdSdS)a` :param current_params: the current params and values for this argument as already entered :param cmd_param: the current command parameter :return: whether or not the last argument is incomplete and corresponds to this cmd_param. In other words whether or not the this cmd_param argument can still accept values FNTr)r&rnamer5r Iterablelen)Zcurrent_paramsr8Zcurrent_param_valuesrrris_incomplete_arguments     r?csTg}t|jtr(fdd|jjD}n(|jdk rP|j||d}dd|D}|S)a :param ctx: context associated with the parsed command :param args: full list of args :param incomplete: the incomplete text to autocomplete :param cmd_param: command definition :return: all the possible user-specified completions for the param cs"g|]}t|r|dfqS)N)str startswith)r0c) incompleterrr2sz,get_user_autocompletions..N)r*r%rCcSs"g|]}t|tr|n|dfqS)N)r&tuple)r0rBrrrr2s)r&typerchoicesautocompletion)r*r%rCr8resultsZdynamic_completionsr)rCrget_user_autocompletionss   rIccs>x8|j|D](}||r|j||}|js|VqWdS)z :param ctx: context associated with the parsed command :starts_with: string that visible commands must start with. :return: all visible (not hidden) commands that start with starts_with. N)r'Z list_commandsrAZ get_commandhidden)r*Z starts_withrBr'rrr"get_visible_commands_starting_withs  rKcstjtr&|ddt|DxTjdk rzjtjtr(jjr(fddt|D}|dd|Dq(WdS)NcSsg|]}|j|fqSr)r<get_short_help_str)r0rBrrrr2sz.add_subcommand_completions..csg|]}|jjkr|qSr)r<r$)r0rB)r*rrr2scSsg|]}|j|fqSr)r<rL)r0rBrrrr2 s)r&r'rextendrKr"r()r*rCZcompletions_outZremaining_commandsr)r*radd_subcommand_completionss   rNc sBt|t|||}|dkr"gSdk}tr\tkr\t}|d|dn tkrhdg}|strxV|jjD]Jt t rj sfddj j D}|fdd|DqW|Sx(|jjD]trt|SqWx.|jjD]"t|jrt|SqWt||t|S) z :param cli: command definition :param prog_name: the program that is running :param args: full list of args :param incomplete: the incomplete text to autocomplete :return: all the possible completions for the incomplete Nz--rrcsg|]}|ksjr|qSr)multiple)r0Z param_opt)r7paramrrr2/szget_choices..cs g|]}|r|jfqSr)rAhelp)r0o)rCrQrrr24s)copydeepcopyr-r.r/ partitionappendr'paramsr&rrJr6Zsecondary_optsrMr:rIr?rNsorted) r)rr%rCr*Zhas_double_dashZpartition_incompleteZ completionsZ param_optsr)r7rCrQr get_choicess8        rZcCsttjd}ttjd}|d|}y ||}Wntk rLd}YnXx>t||||D],}t|d|r^t|dr|dndq^WdS)N COMP_WORDS COMP_CWORDrrrrT)rosenvironint IndexErrorrZr)r)rZinclude_descriptionscwordscwordr%rCitemrrr do_completeEs    rdcCspttjd}tjd}|dd}xFt||||D]4}|dr\tdj|d|ddq4t|dq4WdS)Nr[r\rz {arg} {desc}r)r1descT)rr]r^rZrr)r)rrarCr%rcrrrdo_complete_fishYs  rfcCstd|kr|dd\}}n|}d}|dkr>tt|||dS|dkrp|dkrXt||S|dkrpt|||d kSd S) Nrrr sourceTZcompleter >r r r F)splitrr rfrd)r)rrZcomplete_instrr'rrrr bashcompletegs ri)#rTr]recorerrrparserrtypesrutilsr collectionsr ImportErrorr/rZCOMPLETION_SCRIPT_ZSHZCOMPLETION_SCRIPT_FISHrcompilerr r-r.r:r?rIrKrNrZrdrfrirrrrs@      #  +  5