DdG UddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZd edej$eej(fdedededef dZGddZdZdZdZGddZGddeZGddeZGdd eZej>d!ej@e"Z!eeed#Z"ejFeej@efe$d$< d4d%e!d&ejJede!fd'Z&d(edejJej@efd)Z'd*e d+e de(fd,Z)d*e d-ede(fd.Z*d*e d/ejVed+e de(fd0Z,d edej$eej(fded/ejVede f d1Z-d*e d/ejVed2edej\ej^ee feffd3Z0y)5N)gettext)Argument) BaseCommand)Context) MultiCommand)Option) Parameter)ParameterSource)split_arg_string)echoclictx_args prog_name complete_var instructionreturnc|jd\}}}t|}|y|||||}|dk(rt|jy|dk(rt|j yy)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. _rsourcercomplete) partitionget_completion_classr rr) rrrrrshellrcomp_clscomps 8/usr/lib/python3/dist-packages/click/shell_completion.pyshell_completerss&(11#6E1k#E*H C9l ;Dh T[[]j  T]]_ c eZdZdZdZ d dej dedejedej ddf d Z d edej fd Z y) 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_infoNr#r$r%kwargsrc <||_||_||_||_yNr")selfr#r$r%r's r__init__zCompletionItem.__init__Ls "  %)  rnamec8|jj|Sr))r&get)r*r,s r __getattr__zCompletionItem.__getattr__Xszz~~d##r)plainN) __name__ __module__ __qualname____doc__ __slots__tAnystrOptionalr+r/rrr!r!7sr$3I  $ uu  jjo  %%   $$$rr!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 aXfunction %(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 eZdZUdZej eed< ej eed< dedejeejfdededd f d Z e defd Z dejeejffd Zdefd Zdej"ej$eeffdZdej$ededej$efdZdedefdZdefdZy ) 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_templaterrrrrNc<||_||_||_||_yr))rrrr)r*rrrrs rr+zShellComplete.__init__s!  "(rctjdd|jjddtj}d|dS)zQThe name of the shell function defined by the completion script. z\W*-r _completion)resubrreplaceASCII)r* safe_names r func_namezShellComplete.func_names< FF62t~~'='=c3'GR 9+[))rcJ|j|j|jdS)zVars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. ) complete_funcrr)rHrrr*s r source_varszShellComplete.source_varss%"^^ --  rc<|j|jzS)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=rLrKs rrzShellComplete.sources ##d&6&6&888rct)zUse the env vars defined by the shell script to return a tuple of ``args, incomplete``. This must be implemented by subclasses. NotImplementedErrorrKs rget_completion_argsz!ShellComplete.get_completion_argss "!rargs incompletect|j|j|j|}t |||\}}|j ||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)r*rRrSctxobjs rget_completionszShellComplete.get_completionssEtxxM-c4DZ!!#z22ritemct)zFormat a completion item into the form recognized by the shell script. This must be implemented by subclasses. :param item: Completion item to format. rOr*rZs rformat_completionzShellComplete.format_completions "!rc|j\}}|j||}|Dcgc]}|j|}}dj|Scc}w)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.  )rQrYr]join)r*rRrS completionsrZouts rrzShellComplete.completes[ 335j**4< 8CDt%%d+DDyy~EsA)r1r2r3r4r6ClassVarr8__annotations__rMutableMappingr7r+propertyrHDictrLrTupleListrQr!rYr]rr:rrr<r<s,  **S/ ZZ_$ )  )""3:. ) )  )  )*3**  QVVCJ/  99"QWWQVVC[#-=%>" 3FF3K 3-0 3   3"n"" # rr<ceZdZdZdZeZd dZdeffd Z de je jeeffdZ dedefdZxZS) BashCompletezShell completion for Bash.bashrc@ddl}|jgd|j}tjd|j j }|8|j\}}|dks |dk(r|dkrttdyyttd)Nr)rlz-czecho "${BASH_VERSION}")stdoutz^(\d+)\.(\d+)\.\d+4zCShell completion is not supported for Bash versions older than 4.4.z@Couldn't detect Bash version, shell completion is not supported.) subprocessrunPIPErCsearchrndecodegroups RuntimeErrorr)r*rpoutputmatchmajorminors r_check_versionzBashComplete._check_version0s 4Z__   /1E1E1GH   <<>LE5s{eslus{"40;lTU rc@|jt| Sr))r{superr)r* __class__s rrzBashComplete.sourceGs w~rcttjd}ttjd}|d|} ||}||fS#t$rd}Y||fSwxYwN COMP_WORDS COMP_CWORDrr@r osenvironint IndexErrorr*cwordscwordrRrSs rrQz BashComplete.get_completion_argsKo!"**\":;BJJ|,-a JZ JZ A AArZc8|jd|jS)N,)r$r#r\s rr]zBashComplete.format_completionWs))Adjj\**r)rN)r1r2r3r4r, _SOURCE_BASHr=r{r8rr6rhrirQr!r] __classcell__)r~s@rrkrk*sV$ D"O.    QWWQVVC[#-=%>  +n++rrkcleZdZdZdZeZdejeje e ffdZ de de fdZ y) ZshCompletezShell completion for Zsh.zshrcttjd}ttjd}|d|} ||}||fS#t$rd}Y||fSwxYwrrrs rrQzZshComplete.get_completion_argsarrrZcr|jd|jd|jr|jSdS)Nr_r)r$r#r%r\s rr]zZshComplete.format_completionms7))Btzzl"$))TYY,MNN,MNNrN)r1r2r3r4r, _SOURCE_ZSHr=r6rhrir8rQr!r]r:rrrr[sG# D!O  QWWQVVC[#-=%>  OnOOrrcleZdZdZdZeZdejeje e ffdZ de de fdZ y) FishCompletezShell completion for Fish.fishrcttjd}tjd}|dd}|r|r|d|k(r|j||fS)Nrrr)r rrpop)r*rrSrRs rrQz FishComplete.get_completion_argswsT!"**\":;ZZ - abz $48z#9 HHJZrrZc|jr(|jd|jd|jS|jd|jS)Nr )r%r$r#r\s rr]zFishComplete.format_completionsE 99ii[$**R {; ;))Adjj\**rN)r1r2r3r4r, _SOURCE_FISHr=r6rhrir8rQr!r]r:rrrrqsD$ D"O  QWWQVVC[#-=%>  +n++rrShellCompleteType)bound)rlrr_available_shellsclsr,c4| |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. )r,r)rr,s radd_completion_classrs" |xx!d Jrrc,tj|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 rrrs   ''rrWparamct|tsy|jJ|jj |j}|j dk(xsn|j |jtjuxsA|j dkDxr0t|ttfxrt||j kS)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) isinstancerr,paramsr.nargsget_parameter_sourcer COMMANDLINEtuplelistlen)rWrr#s r_is_incomplete_argumentrs eX & :: !! ! JJNN5:: &E r  # #EJJ /7R7R R  KK!O )55$-0 )E U[[( rr#c.|sy|d}||jvS)z5Check if the value looks like the start of an option.Fr) _opt_prefixes)rWr#cs r_start_of_optionrs"  aA !! !!rrRct|tsy|js |jryd}t t |D](\}}|dz|j kDrnt||s'|}*|duxr||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)rWrRr last_optionindexargs r_is_incomplete_optionrs eV $ }} K/ s 19u{{ "  C %K  d " @{ejj'@@rc:d|d<|j||jfi|}|j|jz}|r|j}t |t r|jsI|j||\}}}||S|j|||d}|j|jz}nd|}|r@|j||\}}}||S|j|||ddd}|j}|r@|}g|j|j}n |S|r|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_parsing)parentrF)rallow_extra_argsallow_interspersed_argsr) make_contextcopyprotected_argsrRcommandrrchainresolve_command) rrrrRrWrr,cmdsub_ctxs rrUrUsF%)H ! #  9diik >X >C    (D ++ g| ,==")"9"9#t"Dc4;J&&tT#QU&V))CHH4&-&=&=c4&HOD#t{" !..")-05*. /G#<rsm  !$# # sAEEz*# #  #  #  # L"$"$L @* X .ggT.+=.+bO-O,+=+2AII1 9NO   9166#qvvm44559 "#**S/((( 166-3H(I(t2"'"#"$"AwAaffSkA)APTA06 6sAEEz*66 &&+ 6  6r,# ,#s ,#14,#WWQWW[)+ ,c 12,#r