;iRUddlmZddlmZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd lmZdCdZGddZdZdZdZGddZGdd eZGd!d"eZGd#d$eZejd%d&'Zeeed(Z d)e!d*< dDdEd.Z"dFd1Z#dGd4Z$dHd:Z%dId<Z&dJd>Z'dKd?Z(dLdBZ)dS)M) annotationsN)gettext)Argument)Command)Context)Group)Option) Parameter)ParameterSource)echoclirctx_argscabc.MutableMapping[str, t.Any] prog_namestr complete_var instructionreturnintc|d\}}}t|}|dS|||||}|dkr#t|dS|dkr#t|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) rrrrrshellrcomp_clscomps JC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\click/shell_completion.pyshell_completer!s&(11#66E1k#E**Hq 8C9l ; ;Dh T[[]]qj   T]]__q 1c,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&t.Anyr'rr( str | NonekwargsrNonec >||_||_||_||_dSNr%)selfr&r'r(r-s r __init__zCompletionItem.__init__Ns$"  $  r"namec6|j|Sr0)r)get)r1r3s r __getattr__zCompletionItem.__getattr__Zsz~~d###r")r*N) r&r+r'rr(r,r-r+rr.)r3rrr+)__name__ __module__ __qualname____doc__ __slots__r2r6r"r r$r$9sZ$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|eZdZUdZded< ded< 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 zt.ClassVar[str]r3source_templaterrrrrrrrr.c>||_||_||_||_dSr0)rrrr)r1rrrrs r r2zShellComplete.__init__s'  "(r"ctjdd|jddtj}d|dS)zQThe name of the shell function defined by the completion script. z\W*-r)flags _completion)resubrreplaceASCII)r1 safe_names r func_namezShellComplete.func_namesA F62t~'='=c3'G'GrxXXX )9))))r"dict[str, t.Any]c,|j|j|jdS)zVars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. ) complete_funcrr)rKrrr1s r source_varszShellComplete.source_varss#"^ -   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`. )r?rPrOs 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. NotImplementedErrorrOs r get_completion_argsz!ShellComplete.get_completion_argss "!r"args list[str] incompletelist[CompletionItem]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!)r1rWrYctxobjs r get_completionszShellComplete.get_completionssHtxMM-c4DDZ!!#z222r"itemr$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. rTr1ras r format_completionzShellComplete.format_completions "!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|]}|Sr<)rd).0rar1s r z*ShellComplete.complete..,s'DDDt%%d++DDDr" )rVr`join)r1rWrY completionsouts` r rzShellComplete.complete#sY 3355j**4<< DDDD DDDyy~~r"N) rrrrrrrrrr.rr)rrLrrR)rWrXrYrrrZrar$rr)r7r8r9r:__annotations__r2propertyrKrPrrVr`rdrr<r"r r>r>s   %$$$ ) ) ) )***X*     9999"""" 3 3 3 3""""      r"r>cTeZdZdZdZeZed dZdfd Z dd Z dd Z xZ S) BashCompletezShell completion for Bash.bashrr.cddl}ddl}|d}|d}nL||dddg|j}t jd|j}|M| \}}|dks |dkr&|dkr"ttd d dSdSdSttd d dS) Nrrtz--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 subprocesswhichrunPIPErFsearchrvdecodegroupsr r)ryrzbash_exematchoutputmajorminors r _check_versionzBashComplete._check_version6s& <<''  EE^^8T+CD!$FI3V]5I5I5K5KLLE   <<>>LE5s{{esllus{{4 +l{{ TUU      r"rcl|tSr0)rsuperr)r1 __class__s r rzBashComplete.sourceWs) ww~~r"rRcttjd}ttjd}|d|} ||}n#t$rd}YnwxYw||fSN COMP_WORDS COMP_CWORDrrBsplit_arg_stringosenvironr IndexErrorr1cwordscwordrWrYs r rVz BashComplete.get_completion_args[x!"*\":;;BJ|,--ag JJ   JJJ Z A A"!A"rar$c$|jd|jS)N,)r'r&rcs r rdzBashComplete.format_completiongs)**dj***r")rr.rmrnro) r7r8r9r:r3 _SOURCE_BASHr? staticmethodrrrVrd __classcell__)rs@r rsrs0s$$ D"O\@           ++++++++r"rsc*eZdZdZdZeZd dZd d Zd S) ZshCompletezShell completion for Zsh.zshrrRcttjd}ttjd}|d|} ||}n#t$rd}YnwxYw||fSrrrs r rVzZshComplete.get_completion_argsqrrrar$rc|jpd}|dkr|jddn|j}|jd|d|S)Nr:z\:ri)r(r&rHr')r1rahelp_r&s r rdzZshComplete.format_completion}sT  S383,, ""3...DJ)//u/////r"Nrnro) r7r8r9r:r3 _SOURCE_ZSHr?rVrdr<r"r rrksL## D!O     000000r"rc*eZdZdZdZeZd dZd d Zd S) FishCompletezShell completion for Fish.fishrrRcttjd}tjd}|rt|d}|dd}|r"|r |d|kr|||fS)Nrrrr)rrrpop)r1rrYrWs r rVz FishComplete.get_completion_argss!"*\":;;Z -  9)*55a8Jabbz  $ 48z#9#9 HHJJJZr"rar$rcd|jr|jd|jd|jS|jd|jS)Nr )r(r'r&rcs r rdzFishComplete.format_completionsF 9 <i;;$*;; ;; ;)**dj***r"Nrnro) r7r8r9r:r3 _SOURCE_FISHr?rVrdr<r"r rrsL$$ D"O     ++++++r"rShellCompleteTypeztype[ShellComplete])bound)rtrrzdict[str, type[ShellComplete]]_available_shellsclsr3r,c,||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. )r3r)rr3s r add_completion_classrs  |x!d Jr"rtype[ShellComplete] | Nonec6t|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. )rr5)rs r rrs   ' ''r"stringrXcddl}||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)posixrB)shlexwhitespace_split commentersappend ValueErrortoken)rrlexrlrs r rrs$LLL ++fD+ ) )CCCN C  E JJu       39  JsA$A/.A/r^rparamr boolc`t|tsdS|jJ|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. FNrr) isinstancerr3paramsr5nargsget_parameter_sourcer COMMANDLINEtuplelistlen)r^rr&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)r^r&cs r _start_of_optionrs& u aA ! !!r"rWct|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)r^rWr last_optionindexargs r _is_incomplete_optionrs 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_argsrWcommandrr chainresolve_command) rrrrWr^rr3cmdsub_ctx sub_sub_ctxs r r\r\2s%)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 ErYtuple[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. =rBz--)rrrr get_paramsrr)r^rWrYr3rrrs r r]r]osS  /Z@@ (22377a D  4,S*=={J&& [ # #C ( (F%% dE 2 2 %*$ $ $ $ % %% "3 . . %*$ $ $ $ % ; ""r") rrrrrrrrrrrrr0)rrr3r,rr)rrrr)rrrrX)r^rrr rr)r^rr&rrr)r^rrWrXrr rr) rrrrrrrWrXrr)r^rrWrXrYrrr)* __future__rcollections.abcabccabcrrFtypingtrrcorerrrr r r r utilsr r!r$rrrr>rsrrTypeVarrrrprrrrrrr\r]r<r"r rs"""""""  !!!!!!# # # # L"$"$"$"$"$"$"$"$L L* X .eeeeeeeeP8+8+8+8+8+=8+8+8+v!0!0!0!0!0-!0!0!0H+++++=+++6AI19NOOO   5504(((((""""J2""""AAAA2::::z,#,#,#,#,#,#r"