U aE@sUddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZeejeejfeeeed ddZGdddZdZdZdZGdddZGdddeZGdddeZGdddeZeeedZejeej efe!d<d4ej eej"eddd d!Z#eej"ej ed"d#d$Z$e e e%d%d&d'Z&ee%d(d)d*Z'ej(ee e%d+d,d-Z)eejeejfeej(ee d.d/d0Z*e ej(eeej+ej,ee fefd1d2d3Z-dS)5N)gettext)Argument) BaseCommand)Context) MultiCommand)Option) Parameter)ParameterSource)split_arg_string)echo)clictx_args prog_name complete_var instructionreturnc Csf|d\}}}t|}|dkr$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_clscomprWC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-s9fh6ldx\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 COMREPLY=() compopt -o dirnames elif [[ $type == 'file' ]]; then COMREPLY=() 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 } compdef %(complete_func)s %(prog_name)s; afunction %(complete_func)s; set -l response; for value in (env %(complete_var)s=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(prog_name)s); set response $response $value; end; 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 ej eej 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(tdd|jddtj}d|dS)zQThe name of the shell function defined by the completion script. z\W*-rZ _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`. )r5r@r?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&rDrEctxobjrrrget_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. NrAr&rLrrrformat_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)rN).0rLr?rr $sz*ShellComplete.complete.. )rCrJjoin)r&rDrEZ completionsoutrr?rrs  zShellComplete.complete)r+r,r-r.r0ClassVarr2__annotations__rDictr1r'propertyr>r@rTupleListrCrrJrNrrrrrr4s(     r4csjeZdZdZdZeZddddZedfdd Z e j e j eefdd d Z eed d d ZZS) BashCompletezShell completion for Bash.bashNr6cCsxddl}|jddg|jd}td|j}|dk rh|\}}|dksZ|dkrt|dkrttt dn tt ddS) Nrr[z --version)stdoutzversion (\d)\.(\d)\.\d4zCShell completion is not supported for Bash versions older than 4.4.z@Couldn't detect Bash version, shell completion is not supported.) subprocessrunPIPEr9searchr\decodegroups RuntimeErrorr)r&r^outputmatchmajorminorrrr_check_version.s zBashComplete._check_versioncs|tSr%)risuperrr? __class__rrrCszBashComplete.sourcecCsVttjd}ttjd}|d|}z ||}Wntk rLd}YnX||fSN COMP_WORDS COMP_CWORDrr7r osenvironint IndexErrorr&cwordscwordrDrErrrrCGs   z BashComplete.get_completion_argsrKcCs|jd|jS)N,)r rrMrrrrNSszBashComplete.format_completion)r+r,r-r.r( _SOURCE_BASHr5rir2rr0rXrYrCrrN __classcell__rrrkrrZ(s rZc@sFeZdZdZdZeZejej e e fdddZ e e dddZ d S) ZshCompletezShell completion for Zsh.zshr6cCsVttjd}ttjd}|d|}z ||}Wntk rLd}YnX||fSrmrprurrrrC]s   zZshComplete.get_completion_argsrKcCs$|jd|jd|jr|jndS)NrQr)r rr!rMrrrrNiszZshComplete.format_completionN)r+r,r-r.r( _SOURCE_ZSHr5r0rXrYr2rCrrNrrrrr{Ws  r{c@sFeZdZdZdZeZejej e e fdddZ e e dddZ d S) FishCompletezShell completion for Fish.fishr6cCsHttjd}tjd}|dd}|r@|r@|d|kr@|||fS)Nrnror)r rqrrpop)r&rvrErDrrrrCss   z FishComplete.get_completion_argsrKcCs2|jr |jd|jd|jS|jd|jS)Nrx )r!r rrMrrrrNszFishComplete.format_completionN)r+r,r-r.r( _SOURCE_FISHr5r0rXrYr2rCrrNrrrrr~ms  r~)r[rr|_available_shells)clsr(rcCs|dkr|j}|t|<dS)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)rHparamrcCsjt|tsdS|jdk st|j|j}|jdkph||jtjk ph|jdkoht|t t foht ||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(AssertionErrorparamsnargsZget_parameter_sourcer Z COMMANDLINEtuplelistlen)rHrrrrr_is_incomplete_arguments      r)rrcCs|r|d SdS)z5Check if the value looks like the start of an option.rF)isalnum)rrrr_start_of_optionsr)rDrrcCsbt|tsdS|jrdSd}tt|D]&\}}|d|jkrBqPt|r(|}q(|dk o`||jkS)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_flag enumeratereversedrropts)rDrZ last_optionindexargrrr_is_incomplete_options r)r rrrDrc Csd|d<|j||f|}|j|j}|r|j}t|tr|js|||\}}}|dkr`|S|j|||dd}|j|j}q|r|||\}}}|dkr|S|j|||dddd}|j}q|}|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_argsrDcommandrrchainZresolve_command) r rrrDrHrr(cmdZsub_ctxrrrrFs:   rF)rHrDrErcCs|dkrd}n*d|kr8t|r8|d\}}}||d|krRt|rR|j|fS|j|}|D]}t||rb||fSqb|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)rHrDrEr(rrrrrrrGs     rG)N).rqr9typingr0rrcorerrrrrr r parserr utilsr rVr2r1rsrrryr}rr4rZr{r~rTyperUr3rrboolrrrYrrFrXUnionrGrrrrsj           && &j/   5