U x6[+@sddlZddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z zddl mZWnek r|ddl ZYnXdZd Zd Zed Zd d ZddZddZddZddZddZddZddZddZddZd d!ZdS)"N)echo)split_arg_string) MultiCommandOptionArgument)Choice)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 a9 %(complete_func)s() { local -a completions local -a completions_with_descriptions local -a response 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 -Q fi if [ -n "$completions" ]; then compadd -U -V unsorted -Q -a completions fi compstate[insert]="automenu" } compdef %(complete_func)s %(script_names)s z [^a-zA-Z0-9_]cCs@td|dd}|dkr tnt}|d|||ddS)N-_zshz_%s_completion)Z complete_funcZ script_namesZautocomplete_var;)_invalid_ident_char_resubreplaceCOMPLETION_SCRIPT_ZSHCOMPLETION_SCRIPT_BASHstrip) prog_name complete_varshellZcf_nameZscriptr5/usr/lib/python3/dist-packages/click/_bashcomplete.pyget_completion_scriptKs rcCs|j||dd}|j|j}|rt|jtr|jjst|j||\}}}|dkrT|S|j|||dd}|j|j}q|r|j||\}}}|dkr|S|j|||dddd}|j}qt|}|j|j}qqq|S)a Parse 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)parentrF)rZallow_extra_argsZallow_interspersed_argsr)Z make_contextprotected_argsargs isinstancecommandrchainZresolve_command)clirrctxZcmd_namecmdZsub_ctxrrr resolve_ctxUs4    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 "--") Nrr r)Z param_strrrrstart_of_optionzsr'cCspt|tsdS|jrdSd}ttdd|DD]&\}}|d|jkrLqZt|r2|}q2|rl||jkrldSdS)aE :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 r3cCs^t|tsdS||j}|dkr$dS|jdkr2dSt|tjrZ|jdkrZt||jkrZdSdS)aL :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 rnamer.r Iterablelen)Zcurrent_paramsr1Zcurrent_param_valuesrrris_incomplete_arguments     r8csTg}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|dfqSN)str startswithr)c incompleterrr+sz,get_user_autocompletions..N)r$rr?cSs"g|]}t|tr|n|dfqSr9)r tupler<rrrr+s)r typerchoicesZautocompletion)r$rr?r1ZresultsZdynamic_completionsrr>rget_user_autocompletionss   rCccs:|j|D](}||r |j||}|js |Vq dS)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_commandsr;Z get_commandhidden)r$Z starts_withr=r!rrr"get_visible_commands_starting_withs  rEcs|tjtr&|ddt|Djdk rxjtjtr&jjr&fddt|D}|dd|Dq&dS)NcSsg|]}|j|fqSrr5Zget_short_help_strr<rrrr+sz.add_subcommand_completions..csg|]}|jjkr|qSr)r5rr<r$rrr+s cSsg|]}|j|fqSrrFr<rrrr+s)r r!rextendrErr")r$r?Zcompletions_outZremaining_commandsrrGradd_subcommand_completionss  rIcs.t|t|||}|dkr"gStrTtkrTt}|d|dn tkr`dg}tr|jjD]Jt t rtj stfddj j D}|fdd|Dqt|S|jjD] trt|Sq|jjD]"t|jrt|Sqt||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 Nrr csg|]}|ksjr|qSr)Zmultiple)r)Z param_opt)r0paramrrr+szget_choices..cs g|]}|r|jfqSr)r;help)r)o)r?rKrrr+s )copydeepcopyr&r'r( partitionappendr!Zparamsr rrDr/Zsecondary_optsrHr3rCr8rIsorted)r#rrr?r$Zpartition_incompleteZ completionsZ param_optsr)r0r?rKr get_choicess6          rScCsttjd}ttjd}|d|}z ||}Wntk rLd}YnXt||||D],}t|d|r\t|dr|dndq\dS)NZ COMP_WORDSZ COMP_CWORDrr rr T)rosenvironint IndexErrorrSr)r#rZinclude_descriptionsZcwordsZcwordrr?itemrrr do_complete s    rYcCsR|dr.|dkrdnd}tt|||dS|dks>|dkrNt|||dkSdS) NsourceZ source_zshrZbashTZcompleteZ complete_zshF)r;rrrY)r#rrZcomplete_instrrrrr bashcompletes r[) rNrTreZutilsrparserrZcorerrrtypesr collectionsr ImportErrorr(rrcompilerrr&r'r3r8rCrErIrSrYr[rrrrs2     % .