a =jgH@sUddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZeejeejfeeeed ddZGdddZdZdZdZGdddZGdddeZGdddeZGdddeZejdej edZ!eeedZ"ej#eej efe$d <d6e!ej%ee!d!d"d#Z&eej%ej ed$d%d&Z'e e e(d'd(d)Z)e ee(d*d+d,Z*e ej+ee e(d-d.d/Z,eejeejfeej+ee d0d1d2Z-e ej+eeej.ej/ee fefd3d4d5Z0dS)7N)gettext)Argument) BaseCommand)Context) MultiCommand)Option) Parameter)ParameterSource)split_arg_string)echo)clictx_args prog_name complete_var instructionreturnc Csf|d\}}}t|}|dur$dS|||||}|dkrJt|dS|dkrbt|dSdS)aPerform shell completion for the given CLI program. :param cli: Command being called. :param ctx_args: Extra arguments to pass to ``cli.make_context``. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. :param instruction: Value of ``complete_var`` with the completion instruction and shell, in the form ``instruction_shell``. :return: Status code to exit with. _Nrsourcercomplete) partitionget_completion_classr rr) r rrrrshellrZcomp_clscompr@/usr/local/lib/python3.9/site-packages/click/shell_completion.pyshell_completes  rc@sHeZdZdZdZd ejeejeejddddZ eejdd d Z dS) CompletionItema)Represents a completion value and metadata about the value. The default metadata is ``type`` to indicate special shell handling, and ``help`` if a shell supports showing a help string next to the value. Arbitrary parameters can be passed when creating the object, and accessed using ``item.attr``. If an attribute wasn't passed, accessing it returns ``None``. :param value: The completion suggestion. :param type: Tells the shell script to provide special completion support for the type. Click uses ``"dir"`` and ``"file"``. :param help: String shown next to the value if supported. :param kwargs: Arbitrary metadata. The built-in implementations don't use this, but custom type completions paired with custom shell support could use it. valuetypehelp_infoplainN)rr r!kwargsrcKs||_||_||_||_dSNr)selfrr r!r$rrr__init__LszCompletionItem.__init__)namercCs |j|Sr%)r"get)r&r(rrr __getattr__XszCompletionItem.__getattr__)r#N) __name__ __module__ __qualname____doc__ __slots__tAnystrOptionalr'r*rrrrr7s ra%(complete_func)s() { local IFS=$'\n' local response response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD %(complete_var)s=bash_complete $1) for completion in $response; do IFS=',' read type value <<< "$completion" if [[ $type == 'dir' ]]; then COMPREPLY=() compopt -o dirnames elif [[ $type == 'file' ]]; then COMPREPLY=() compopt -o default elif [[ $type == 'plain' ]]; then COMPREPLY+=($value) fi done return 0 } %(complete_func)s_setup() { complete -o nosort -F %(complete_func)s %(prog_name)s } %(complete_func)s_setup; a#compdef %(prog_name)s %(complete_func)s() { local -a completions local -a completions_with_descriptions local -a response (( ! $+commands[%(prog_name)s] )) && return 1 response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) %(complete_var)s=zsh_complete %(prog_name)s)}") for type key descr in ${response}; do if [[ "$type" == "plain" ]]; then if [[ "$descr" == "_" ]]; then completions+=("$key") else completions_with_descriptions+=("$key":"$descr") fi elif [[ "$type" == "dir" ]]; then _path_files -/ elif [[ "$type" == "file" ]]; then _path_files -f 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 } if [[ $zsh_eval_context[-1] == loadautofunc ]]; then # autoload from fpath, call function directly %(complete_func)s "$@" else # eval/source/. command, register function for later compdef %(complete_func)s %(prog_name)s fi affunction %(complete_func)s; set -l response (env %(complete_var)s=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(prog_name)s); for completion in $response; set -l metadata (string split "," $completion); if test $metadata[1] = "dir"; __fish_complete_directories $metadata[2]; else if test $metadata[1] = "file"; __fish_complete_path $metadata[2]; else if test $metadata[1] = "plain"; echo $metadata[2]; end; end; end; complete --no-files --command %(prog_name)s --arguments "(%(complete_func)s)"; c@seZdZUdZejeed<ejeed<eej eej feeddddZ e edd d Z ejeej fdd d Zedd dZejejeefdddZejeeejedddZeedddZedddZdS) ShellCompleteaBase class for providing shell completion support. A subclass for a given shell will override attributes and methods to implement the completion instructions (``source`` and ``complete``). :param cli: Command being called. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. .. versionadded:: 8.0 r(source_templateN)r rrrrcCs||_||_||_||_dSr%)r rrr)r&r rrrrrrr'szShellComplete.__init__rcCs*tjdd|jddtjd}d|dS)zQThe name of the shell function defined by the completion script. z\W*-r)flagsZ _completion)resubrreplaceASCII)r& safe_namerrr func_nameszShellComplete.func_namecCs|j|j|jdS)zVars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. )Z complete_funcrr)r?rrr&rrr source_varsszShellComplete.source_varscCs|j|S)zProduce the shell script that defines the completion function. By default this ``%``-style formats :attr:`source_template` with the dict returned by :meth:`source_vars`. )r5rAr@rrrrszShellComplete.sourcecCstdS)zUse the env vars defined by the shell script to return a tuple of ``args, incomplete``. This must be implemented by subclasses. NNotImplementedErrorr@rrrget_completion_argssz!ShellComplete.get_completion_args)args incompletercCs0t|j|j|j|}t|||\}}|||S)aTDetermine the context and last complete command or parameter from the complete args. Call that object's ``shell_complete`` method to get the completions for the incomplete value. :param args: List of complete args before the incomplete value. :param incomplete: Value being completed. May be empty. )_resolve_contextr rr_resolve_incompleter)r&rErFctxobjrrrget_completionss zShellComplete.get_completionsitemrcCstdS)zFormat a completion item into the form recognized by the shell script. This must be implemented by subclasses. :param item: Completion item to format. NrBr&rMrrrformat_completionszShellComplete.format_completioncs4\}}||}fdd|D}d|S)zProduce the completion data to send back to the shell. By default this calls :meth:`get_completion_args`, gets the completions, then calls :meth:`format_completion` for each completion. csg|]}|qSr)rO).0rMr@rr &z*ShellComplete.complete.. )rDrKjoin)r&rErFZ completionsoutrr@rrs  zShellComplete.complete)r+r,r-r.r0ClassVarr2__annotations__rMutableMappingr1r'propertyr?DictrArTupleListrDrrKrOrrrrrr4s&      r4csneZdZdZdZeZeddddZe dfdd Z e j e j e e fdd d Zee d d d ZZS) BashCompletezShell completion for Bash.bashNr6cCsddl}ddl}|d}|dur(d}n*|j|dddg|jd}td|j}|dur| \}}|dks~|dkr|dkrt t d d d nt t d d d dS) Nrr^z--norcz-czecho "${BASH_VERSION}")stdoutz^(\d+)\.(\d+)\.\d+4zCShell completion is not supported for Bash versions older than 4.4.T)errz@Couldn't detect Bash version, shell completion is not supported.) shutil subprocesswhichrunPIPEr:searchr_decodegroupsr r)rbrcZbash_exematchoutputmajorminorrrr_check_version0s.   zBashComplete._check_versioncs|tSr%)rnsuperrr@ __class__rrrQszBashComplete.sourcecCsTttjd}ttjd}|d|}z ||}WntyJd}Yn0||fSN COMP_WORDS COMP_CWORDrr7r osenvironint IndexErrorr&cwordscwordrErFrrrrDUs    z BashComplete.get_completion_argsrLcCs|jd|jS)N,)r rrNrrrrOaszBashComplete.format_completion)r+r,r-r.r( _SOURCE_BASHr5 staticmethodrnr2rr0r[r\rDrrO __classcell__rrrprr]*s  r]c@sFeZdZdZdZeZejej e e fdddZ e e dddZ d S) ZshCompletezShell completion for Zsh.zshr6cCsTttjd}ttjd}|d|}z ||}WntyJd}Yn0||fSrrrurzrrrrDks    zZshComplete.get_completion_argsrLcCs$|jd|jd|jr|jndS)NrSr)r rr!rNrrrrOwszZshComplete.format_completionN)r+r,r-r.r( _SOURCE_ZSHr5r0r[r\r2rDrrOrrrrres  rc@sFeZdZdZdZeZejej e e fdddZ e e dddZ d S) FishCompletezShell completion for Fish.fishr6cCsHttjd}tjd}|dd}|r@|r@|d|kr@|||fS)Nrsrtr)r rvrwpop)r&r{rFrErrrrDs   z FishComplete.get_completion_argsrLcCs2|jr |jd|jd|jS|jd|jS)Nr} )r!r rrNrrrrOszFishComplete.format_completionN)r+r,r-r.r( _SOURCE_FISHr5r0r[r\r2rDrrOrrrrr{s  rShellCompleteType)bound)r^rr_available_shells)clsr(rcCs|dur|j}|t|<|S)amRegister a :class:`ShellComplete` subclass under the given name. The name will be provided by the completion instruction environment variable during completion. :param cls: The completion class that will handle completion for the shell. :param name: Name to register the class under. Defaults to the class's ``name`` attribute. N)r(r)rr(rrradd_completion_classs r)rrcCs t|S)zLook up a registered :class:`ShellComplete` subclass by the name provided by the completion instruction environment variable. If the name isn't registered, returns ``None``. :param shell: Name the class is registered under. )rr))rrrrrsr)rIparamrcCslt|tsdS|jdusJ|j|j}|jdkpj||jtjupj|jdkojt|t t fojt ||jkS)zDetermine if the given parameter is an argument that can still accept values. :param ctx: Invocation context for the command represented by the parsed complete args. :param param: Argument object being checked. FNrr) isinstancerr(paramsr)nargsZget_parameter_sourcer Z COMMANDLINEtuplelistlen)rIrrrrr_is_incomplete_arguments     r)rIrrcCs|sdS|d}||jvS)z5Check if the value looks like the start of an option.Fr)Z _opt_prefixes)rIrcrrr_start_of_optionsr)rIrErrcCsjt|tsdS|js|jrdSd}tt|D](\}}|d|jkrHqXt||r.|}q.|duoh||jvS)zDetermine if the given parameter is an option that needs a value. :param args: List of complete args before the incomplete value. :param param: Option object being checked. FNr) rrZis_flagcount enumeratereversedrropts)rIrErZ last_optionindexargrrr_is_incomplete_options   r)r rrrErc Csd|d<|j||fi|}|j|j}|r|j}t|tr|js|||\}}}|durd|S|j|||dd}|j|j}q|}|r|||\}}}|dur|S|j|||dddd}|j}q|}g|j|j}q,qq,|S)a`Produce the context hierarchy starting with the command and traversing the complete arguments. This only follows the commands, it doesn't trigger input prompts or callbacks. :param cli: Command being called. :param prog_name: Name of the executable in the shell. :param args: List of complete args before the incomplete value. Tresilient_parsingN)parentrF)rZallow_extra_argsallow_interspersed_argsr) Z make_contextcopyZprotected_argsrEcommandrrchainZresolve_command) r rrrErIrr(cmdZsub_ctxrrrrGs<  rG)rIrErFrcCs|dkrd}n,d|vr:t||r:|d\}}}||d|vrVt||rV|j|fS|j|}|D]}t|||rf||fSqf|D]}t||r||fSq|j|fS)ahFind the Click object that will handle the completion of the incomplete value. Return the object and the incomplete value. :param ctx: Invocation context for the command represented by the parsed complete args. :param args: List of complete args before the incomplete value. :param incomplete: Value being completed. May be empty. =r7z--)rrappendr get_paramsrr)rIrErFr(rrrrrrrH/s     rH)N)1rvr:typingr0rrcorerrrrrr r parserr utilsr rXr2r1rxrrr~rrr4r]rrTypeVarTyperrrZrWr3rrboolrrr\rrGr[UnionrHrrrrsd            && ,j;     :