B x `0ã@sddlZddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ydd l mZWnek rŒddl ZYnXd Zd Zd Zd ZeeedœZe d¡Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd 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 z¯complete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)")ÚbashÚzshÚfishz [^a-zA-Z0-9_]cCs>t d| dd¡¡}t |t¡}|d |¡||dœ ¡dS)NÚú-Ú_z_{}_completion)Z complete_funcZ script_namesZautocomplete_varú;)Ú_invalid_ident_char_reÚsubÚreplaceÚ_completion_scriptsÚgetÚCOMPLETION_SCRIPT_BASHÚformatÚstrip)Ú prog_nameÚ complete_varÚshellZcf_nameÚscript©rú7/tmp/pip-unpacked-wheel-za9e8r29/click/_bashcomplete.pyÚget_completion_script_s  r cCsØ|j||dd�}|j|j}x¶|rÒt|jtƒrÎ|jjsv|j ||¡\}}}|dkrV|S|j|||dd�}|j|j}qÐxD|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_argsÚallow_interspersed_argsr!)Z make_contextÚprotected_argsÚargsÚ isinstanceÚcommandrÚchainZresolve_command)Úclirr%ÚctxÚcmd_nameÚcmdZsub_ctxrrrÚ resolve_ctxls6    r-cCs|o|dd…dkS)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_strrrrÚstart_of_option—sr.cCsrt|tƒsdS|jrdSd}x>ttdd„|DƒƒƒD]$\}}|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)Ú.0Úargrrrú ¯sz(is_incomplete_option..rT)r&rZis_flagÚ enumerateÚreversedÚnargsr.Úopts)Úall_argsÚ cmd_paramZ last_optionÚindexZarg_strrrrÚis_incomplete_option s r:cCs^t|tƒsdS||j}|dkr$dS|jdkr2dSt|tjƒrZ|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 FNTéÿÿÿÿr)r&rÚnamer5r ÚIterableÚlen)Zcurrent_paramsr8Zcurrent_param_valuesrrrÚis_incomplete_argument¹s     r?csTg}t|jtƒr(‡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|df‘qS)N)ÚstrÚ startswith)r0Úc)Ú incompleterrr2Þsz,get_user_autocompletions..N)r*r%rCcSs"g|]}t|tƒr|n|df‘qS)N)r&Útuple)r0rBrrrr2ås)r&ÚtyperÚchoicesÚautocompletion)r*r%rCr8ÚresultsZdynamic_completionsr)rCrÚget_user_autocompletionsÒs   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_commandÚhidden)r*Z starts_withrBr'rrrÚ"get_visible_commands_starting_withês  rKcs€tˆjtƒr&| dd„tˆ|ƒDƒ¡xTˆjdk rzˆj‰tˆjtƒr(ˆjjr(‡fdd„tˆ|ƒDƒ}| dd„|Dƒ¡q(WdS)NcSsg|]}|j| ¡f‘qSr)r<Úget_short_help_str)r0rBrrrr2üsz.add_subcommand_completions..csg|]}|jˆjkr|‘qSr)r<r$)r0rB)r*rrr2scSsg|]}|j| ¡f‘qSr)r<rL)r0rBrrrr2 s)r&r'rÚextendrKr"r()r*rCZcompletions_outZremaining_commandsr)r*rÚadd_subcommand_completions÷s   rNc sBt |¡‰t|||ƒ}|dkr"gSdˆk}tˆƒr\tˆkr\ˆ t¡}ˆ |d¡|d‰n ˆtkrhd‰g}|sÔtˆƒrÔxV|jjD]J‰t ˆt ƒr‚ˆj s‚‡‡fdd„ˆj ˆj Dƒ}| ‡‡fdd„|Dƒ¡q‚W|Sx(|jjD]‰tˆˆƒrÞt|ˆˆˆƒSqÞWx.|jjD]"‰t|jˆƒ�rt|ˆˆˆƒS�qWt|ˆ|ƒ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--rércsg|]}|ˆksˆjr|‘qSr)Úmultiple)r0Z param_opt)r7Úparamrrr2/szget_choices..cs g|]}| ˆ¡r|ˆjf‘qSr)rAÚhelp)r0Úo)rCrQrrr24s)ÚcopyÚdeepcopyr-r.r/Ú partitionÚappendr'Úparamsr&rrJr6Zsecondary_optsrMr:rIr?rNÚsorted) r)rr%rCr*Zhas_double_dashZpartition_incompleteZ completionsZ param_optsr)r7rCrQrÚ get_choicess8        rZcCs’ttjdƒ}ttjdƒ}|d|…}y ||}Wntk rLd}YnXx>t||||ƒD],}t|dƒ|r^t|dr„|dndƒq^WdS)NÚ COMP_WORDSÚ COMP_CWORDrrrrT)rÚosÚenvironÚintÚ IndexErrorrZr)r)rZinclude_descriptionsÚcwordsÚcwordr%rCÚitemrrrÚ do_completeEs    rdcCspttjdƒ}tjd}|dd…}xFt||||ƒD]4}|dr\tdj|d|dd�ƒq4t|dƒq4WdS)Nr[r\rz {arg} {desc}r)r1ÚdescT)rr]r^rZrr)r)rrarCr%rcrrrÚdo_complete_fishYs  rfcCstd|kr| dd¡\}}n|}d}|dkr>tt|||ƒƒdS|dkrp|dkrXt||ƒS|dkrpt|||d kƒSd S) Nrrr ÚsourceTZcompleter >r r r F)Úsplitrr rfrd)r)rrZcomplete_instrr'rrrrÚ bashcompletegs ri)#rTr]ÚreÚcorerrrÚparserrÚtypesrÚutilsrÚ collectionsr Ú ImportErrorr/rZCOMPLETION_SCRIPT_ZSHZCOMPLETION_SCRIPT_FISHrÚcompilerr r-r.r:r?rIrKrNrZrdrfrirrrrÚs@      #  +  5