4V=jZXUddlmZddlmZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd lmZdTdZejrddlmZeddejZnejddZGddejeZdZd Zd!ZGd"d#ej Z!Gd$d%Z"Gd&d'e"Z#Gd(d)e"Z$Gd*d+e"Z%e#e%e$d,Z&d-e'd.<ejd/d%0Z( dUdVd5Z)ej*dWd9Z+ej*dXd<Z+ej*dYd?Z+ej*dZdAZ+dZdBZ+d[dEZ,d\dKZ-d]dMZ.d^dOZ/d_dPZ0d`dSZ1dS)a) annotationsN)gettext)Argument)Command)Context)Group)Option) Parameter)ParameterSource)echoclirctx_argscabc.MutableMapping[str, t.Any] prog_namestr complete_var instructionreturnt.Literal[0, 1]cj|d\}}}t|}|dS|||||}|dkr7t|ddS|dkr5t|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. _NrsourceF)nlrcomplete) partitionget_completion_classr rencoder) rrrrrshellrcomp_clscomps DC:\PYTHON\_runtimes\venv\Lib\site-packages\click/shell_completion.pyshell_completer#s&(11#66E1k#E**Hq 8C9l ; ;Dh T[[]] ! ! # #....qj   T]]__ # # % %&&&q 1)TypeVar _ValueT_coT) covariantdefault)r'c,eZdZdZdZ dddZddZdS)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_infoplainNr,r&r-rr. str | Nonekwargst.AnyrNonec >||_||_||_||_dSNr+)selfr,r-r.r2s r"__init__zCompletionItem.__init__Xs$"'  $  r$namec6|j|Sr6)r/get)r7r9s r" __getattr__zCompletionItem.__getattr__dsz~~d###r$)r0N) r,r&r-rr.r1r2r3rr4)r9rrr3)__name__ __module__ __qualname____doc__ __slots__r8r<r$r"r*r*CsZ$3I      $$$$$$r$r*a%(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.eZdZUded<ded<ded<dS)_SourceVarsDictr complete_funcrrN)r=r>r?__annotations__rBr$r"rDrDs1NNNNNr$rDceZdZUdZded< ded< ded<ded<d ed <d ed <ddZed dZd!dZd dZ d"dZ d#dZ d$dZ d dZ dS)% 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 t.ClassVar[str]r9source_templaterrrrrrrrr4c>||_||_||_||_dSr6)rrrr)r7rrrrs r"r8zShellComplete.__init__s'  "(r$ctjdd|jddtj}d|dS)zQThe name of the shell function defined by the completion script. z\W*-r)flags _completion)resubrreplaceASCII)r7 safe_names r" func_namezShellComplete.func_namesA F62t~'='=c3'G'GrxXXX )9))))r$rDc,|j|j|jdS)zVars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. )rErr)rVrrr7s r" source_varszShellComplete.source_vars s#"^ -   r$c:|j|zS)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`. )rJrYrXs r"rzShellComplete.sources #d&6&6&8&888r$tuple[list[str], str]ct)zUse the env vars defined by the shell script to return a tuple of ``args, incomplete``. This must be implemented by subclasses. NotImplementedErrorrXs r"get_completion_argsz!ShellComplete.get_completion_argss "!r$args list[str] incompletelist[CompletionItem[str]]ct|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_contextrrr_resolve_incompleter#)r7r`rbctxobjs r"get_completionszShellComplete.get_completions$sHtxMM-c4DDZ!!#z222r$itemCompletionItem[str]ct)zFormat a completion item into the form recognized by the shell script. This must be implemented by subclasses. :param item: Completion item to format. r]r7rjs r"format_completionzShellComplete.format_completion2s "!r$c\}}||}fd|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. c:g|]}|SrB)rn).0rjr7s r" z*ShellComplete.complete..Cs'DDDt%%d++DDDr$ )r_rijoin)r7r`rb completionsouts` r"rzShellComplete.complete:sY 3355j**4<< DDDD DDDyy~~r$N) rrrrrrrrrr4rr)rrDrr[)r`rarbrrrcrjrkrr)r=r>r?r@rFr8propertyrVrYrr_rirnrrBr$r"rHrHs   %$$$LLL----NNN ) ) ) )***X*     9999"""" 3 3 3 3""""      r$rHcjeZdZUdZdZded<eZded<eddZ dfd Z dd Z ddZ xZ S) BashCompletezShell completion for Bash.bashrIr9rJrr4cddl}ddl}|d}|d}nL||dddg|j}t jd|j}|M| \}}|dks |dkr&|dkr"ttd d dSdSdSttd 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 subprocesswhichrunPIPErQsearchrdecodegroupsr r)rrbash_exematchoutputmajorminors r"_check_versionzBashComplete._check_versionMs& <<''  EE^^8T+CD!$FI3V]5I5I5K5KLLE   <<>>LE5s{{esllus{{4 +l{{ TUU      r$rcl|tSr6)rsuperr)r7 __class__s r"rzBashComplete.sourcens) ww~~r$r[cttjd}ttjd}|d|} ||}n#t$rd}YnwxYw||fSN COMP_WORDS COMP_CWORDrrMsplit_arg_stringosenvironint IndexErrorr7cwordscwordr`rbs r"r_z BashComplete.get_completion_argsrx!"*\":;;BJ|,--ag JJ   JJJ Z A A"!A"rjCompletionItem[t.Any]c$|jd|jS)N,)r-r,rms r"rnzBashComplete.format_completion~s)**dj***r$)rr4rwrx)rjrrr)r=r>r?r@r9rF _SOURCE_BASHrJ staticmethodrrr_rn __classcell__)rs@r"r|r|Gs$$"D""""'3O3333\@           ++++++++r$r|c@eZdZUdZdZded<eZded<ddZdd Z d S) ZshCompletezShell completion for Zsh.zshrIr9rJrr[cttjd}ttjd}|d|} ||}n#t$rd}YnwxYw||fSrrrs r"r_zZshComplete.get_completion_argsrrrjrkrc|jpd}|dkr|jddn|j}|jd|d|S)Nr:z\:rs)r.r,rSr-)r7rjhelp_r,s r"rnzZshComplete.format_completionsT  S383,, ""3...DJ)//u/////r$Nrxry) r=r>r?r@r9rF _SOURCE_ZSHrJr_rnrBr$r"rrsf##!D!!!!'2O2222     000000r$rc@eZdZUdZdZded<eZded<ddZdd Z d S) FishCompletezShell completion for Fish.fishrIr9rJrr[cttjd}tjd}|rt|d}|dd}|r"|r |d|kr|||fS)Nrrrr)rrrpop)r7rrbr`s r"r_z FishComplete.get_completion_argss!"*\":;;Z -  9)*55a8Jabbz  $ 48z#9#9 HHJJJZr$rjrkrc|jrC|jdddd}|jd|jd|S|jd|jS)z .. versionchanged:: 8.4.2 Escape newlines and replace tabs with spaces in the help text to fix completion errors with multi-line help strings. rsz\n  r)r.rSr-r,)r7rjrs r"rnzFishComplete.format_completionsm 9 8I%%dE22::4EEEi77$*7777 7)**dj***r$Nrxry) r=r>r?r@r9rF _SOURCE_FISHrJr_rnrBr$r"rrsf$$"D""""'3O3333     ++++++r$r)r}rrz't.Final[dict[str, type[ShellComplete]]]_available_shells_ShellCompleteT)boundclstype[_ShellCompleteT]r9r1c,||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. )r9r)rr9s r"add_completion_classrs  |x!d Jr$rt.Literal['bash']type[BashComplete]cdSr6rBrs r"rrJM#r$t.Literal['fish']type[FishComplete]cdSr6rBrs r"rrrr$t.Literal['zsh']type[ZshComplete]cdSr6rBrs r"rrsHKr$type[ShellComplete] | NonecdSr6rBrs r"rrsDGCr$c6t|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;rs r"rrs   ' ''r$stringracddl}||d}d|_d|_g} |D]}||n*#t$r||jYnwxYw|S)aSplit an argument string as with :func:`shlex.split`, but don't fail if the string is incomplete. Ignores a missing closing quote or incomplete escape sequence and uses the partial token as-is. .. code-block:: python split_arg_string("example 'my file") ["example", "my file"] split_arg_string("example my\") ["example", "my"] :param string: String to split. .. versionchanged:: 8.2 Moved to ``shell_completion`` from ``parser``. rNT)posixrM)shlexwhitespace_split commentersappend ValueErrortoken)rrlexrvrs r"rrs$LLL ++fD+ ) )CCCN C  E JJu       39  JsA$A/.A/rgrparamr boolcNt|tsdS|j|j}|jdkpd||jtjup>|jdko3t|ttfot||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. Frr) isinstancerparamsr;r9nargsget_parameter_sourcer COMMANDLINEtuplelistlen)rgrr,s r"_is_incomplete_argumentrs eX & &u JNN5: & &E r  # #EJ / /7R R  K!O )55$-00 )E U[( r$r,c,|sdS|d}||jvS)z5Check if the value looks like the start of an option.Fr) _opt_prefixes)rgr,cs r"_start_of_optionr6s& u aA ! !!r$r`ct|tsdS|js|jrdSd}t t |D])\}}|dz|jkrnt||r|}n*|duo||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) rr is_flagcount enumeratereversedrropts)rgr`r last_optionindexargs r"_is_incomplete_optionr?s eV $ $u } uK// s 19u{ " " E C % % K E  d " @{ej'@@r$c d|d<|j||fi|5}|j|jz}|r|j}t |t r|jsm|||\}}}||cdddS||||d5}|}|j|jz}dddn #1swxYwYn|}|rh|||\}}}||cdddS||||ddd5} | }|j}dddn #1swxYwY|h|}g|j|j}nn|dddn #1swxYwY|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)rallow_extra_argsallow_interspersed_argsr) make_contextcopy_protected_argsr`commandrr chainresolve_command) rrrr`rgrr9cmdsub_ctx sub_sub_ctxs r"rereXs%)H !  )TYY[[ = =H = =)"SX-& kG'5))# } E&-&=&=c4&H&HOD#t{"))))))))))d3$*> %"2SX= >>>>>>>>>>>>>>> "G0*1*A*A#t*L*Lc4;#&3))))))))6!--  #&-149.2 . 0)&1G#*2 E>C EC %E8E D) E)D- -E0D- 1EE Erbtuple[Command | Parameter, str]c|dkrd}nBd|vr>t||r.|d\}}}||d|vrt||r |j|fS|j|}|D]}t |||r||fcS|D]}t ||r||fcS|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. =rMz--)rrrr get_paramsrr)rgr`rbr9rrrs r"rfrfsS  /Z@@ (22377a D  4,S*=={J&& [ # #C ( (F%% dE 2 2 %*$ $ $ $ % %% "3 . . %*$ $ $ $ % ; ""r$) rrrrrrrrrrrrr6)rrr9r1rr)rrrr)rrrr)rrrr)rrrr)rrrra)rgrrr rr)rgrr,rrr)rgrr`rarr rr) rrrrrrr`rarr)rgrr`rarbrrr)2 __future__rcollections.abcabccabcrrQtypingtrrcorerrrr r r r utilsr r# TYPE_CHECKINGtyping_extensionsr%Anyr&Genericr*rrr TypedDictrDrHr|rrrrFrroverloadrrrrrrerfrBr$r"rs"""""""  !!!!!!$ $ $ $ N?9))))))quEEEJJ<4888J"$"$"$"$"$QYz*"$"$"$L L* X .ak llllllll^8+8+8+8+8+=8+8+8+v!0!0!0!0!0-!0!0!0H"+"+"+"+"+="+"+"+L   >> !)-_EEE48(MMM MMMM MKKK KGGG G((((""""J.""""AAAA2::::z,#,#,#,#,#,#r$