zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
U
ß=®dÜGã@sUddlZddlZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
ddlm Z dd    lm Z dd
lm Z dd lmZdd lmZeejeejfeeeed œdd„ZGdd„dƒZdZdZdZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZejdej edZ!eeedœZ"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    d0œd1d2„Z-e    ej+eeej.ej/ee fefd3œd4d5„Z0dS)7éN)Úgettexté)ÚArgument)Ú BaseCommand)ÚContext)Ú MultiCommand)ÚOption)Ú    Parameter)ÚParameterSource)Úsplit_arg_string)Úecho)ÚcliÚctx_argsÚ    prog_nameÚ complete_varÚ instructionÚreturnc    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.
    Ú_NrÚsourcerÚcomplete)Ú    partitionÚget_completion_classr rr)    r rrrrÚshellrZcomp_clsÚcomp©rúMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\click/shell_completion.pyÚshell_completes  rc@sHeZdZdZdZd ejeejeejddœdd„Z    eejdœd    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.
    ©ÚvalueÚtypeÚhelpÚ_infoÚplainN)rr r!ÚkwargsrcKs||_||_||_||_dS©Nr)Ú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__ÚtÚAnyÚstrÚOptionalr'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
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@säeZdZUdZejeed<ejeed<eej    eej
feeddœdd„Z e edœd    d
„ƒZ ejeej
fdœd d „Zedœd d„Zejejeefdœdd„Zejeeejedœdd„Zeedœdd„Zedœdd„ZdS)Ú ShellCompletea¯Base 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(t dd|j dd¡tj¡}d|›dS)zQThe name of the shell function defined by the completion
        script.
        z\W*Úú-rZ _completion)ÚreÚsubrÚreplaceÚASCII)r&Ú    safe_namerrrÚ    func_nameäszShellComplete.func_namecCs|j|j|jdœS)z—Vars for formatting :attr:`source_template`.
 
        By default this provides ``complete_func``, ``complete_var``,
        and ``prog_name``.
        )Z complete_funcrr)r>rr©r&rrrÚ source_varsìsýzShellComplete.source_varscCs|j| ¡S)zÊProduce 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?rrrrøszShellComplete.sourcecCst‚dS)z˜Use the env vars defined by the shell script to return a
        tuple of ``args, incomplete``. This must be implemented by
        subclasses.
        N©ÚNotImplementedErrorr?rrrÚget_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&rDrEÚctxÚobjrrrÚget_completionss
zShellComplete.get_completions©ÚitemrcCst‚dS)z°Format a completion item into the form recognized by the
        shell script. This must be implemented by subclasses.
 
        :param item: Completion item to format.
        NrA©r&rLrrrÚformat_completionszShellComplete.format_completioncs4ˆ ¡\}}ˆ ||¡}‡fdd„|Dƒ}d |¡S)zÛProduce 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Ú
<listcomp>&sz*ShellComplete.complete.<locals>.<listcomp>Ú
)rCrJÚjoin)r&rDrEZ completionsÚoutrr?rrs  zShellComplete.complete)r+r,r-r.r0ÚClassVarr2Ú__annotations__rÚMutableMappingr1r'Úpropertyr>ÚDictr@rÚTupleÚListrCrrJrNrrrrrr4Às(
 ú  þ r4csjeZdZdZdZeZddœdd„Zedœ‡fdd„ Z    e
j e
j eefdœd    d
„Z eed œd d „Z‡ZS)Ú BashCompletezShell completion for Bash.ÚbashNr6cCszddl}|jdddg|jd}t d|j ¡¡}|dk    rj| ¡\}}|dks\|dkrv|dkrvtt    dƒƒ‚n tt    d    ƒƒ‚dS)
Nrr\z-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.)
Ú
subprocessÚrunÚPIPEr9Úsearchr]ÚdecodeÚgroupsÚ RuntimeErrorr)r&r_ÚoutputÚmatchÚmajorÚminorrrrÚ_check_version0s"ÿ ÿÿÿzBashComplete._check_versioncs| ¡tƒ ¡Sr%)rjÚsuperrr?©Ú    __class__rrrGszBashComplete.sourcecCsVttjdƒ}ttjdƒ}|d|…}z ||}Wntk
rLd}YnX||fS©NÚ
COMP_WORDSÚ
COMP_CWORDrr7©r ÚosÚenvironÚintÚ
IndexError©r&ÚcwordsÚcwordrDrErrrrCKs  
z BashComplete.get_completion_argsrKcCs|j›d|j›S)Nú,)r rrMrrrrNWszBashComplete.format_completion)r+r,r-r.r(Ú _SOURCE_BASHr5rjr2rr0rYrZrCrrNÚ __classcell__rrrlrr[*s r[c@sFeZdZdZdZeZejej    e
e
fdœdd„Z e e
dœdd„Z d    S)
Ú ZshCompletezShell completion for Zsh.Úzshr6cCsVttjdƒ}ttjdƒ}|d|…}z ||}Wntk
rLd}YnX||fSrnrqrvrrrrCas  
zZshComplete.get_completion_argsrKcCs$|j›d|j›d|jr|jnd›S)NrQr)r rr!rMrrrrNmszZshComplete.format_completionN)r+r,r-r.r(Ú _SOURCE_ZSHr5r0rYrZr2rCrrNrrrrr|[s
 r|c@sFeZdZdZdZeZejej    e
e
fdœdd„Z e e
dœdd„Z d    S)
Ú FishCompletezShell completion for Fish.Úfishr6cCsHttjdƒ}tjd}|dd…}|r@|r@|d|kr@| ¡||fS)Nrorpréÿÿÿÿ)r rrrsÚpop)r&rwrErDrrrrCws 
 z FishComplete.get_completion_argsrKcCs2|jr |j›d|j›d|j›S|j›d|j›S)Nryú    )r!r rrMrrrrNƒszFishComplete.format_completionN)r+r,r-r.r(Ú _SOURCE_FISHr5r0rYrZr2rCrrNrrrrrqs
 rÚShellCompleteType)Úbound)r\r€r}Ú_available_shells)Úclsr(rcCs|dkr|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‡)rˆr(rrrÚadd_completion_class”s r‰)rrcCs
t |¡S)zñLook 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.
    )r‡r))rrrrr¨sr)rHÚparamrcCslt|tƒsdS|jdk    st‚|j |j¡}|jdkpj| |j¡tj    k    pj|jdkojt|t
t fƒojt |ƒ|jkS)zìDetermine 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.
    FNrr) Ú
isinstancerr(ÚAssertionErrorÚparamsr)ÚnargsZget_parameter_sourcer
Z COMMANDLINEÚtupleÚlistÚlen)rHrŠrrrrÚ_is_incomplete_argument²s
 
ÿ
 ÿ úr’)rHrrcCs|sdS|d}||jkS)z5Check if the value looks like the start of an option.Fr)Z _opt_prefixes)rHrÚcrrrÚ_start_of_optionËsr”)rHrDrŠrcCsjt|tƒsdS|js|jrdSd}tt|ƒƒD](\}}|d|jkrHqXt||ƒr.|}q.|dk    oh||jkS)zºDetermine 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)    r‹rZis_flagÚcountÚ    enumerateÚreversedrŽr”Úopts)rHrDrŠZ last_optionÚindexÚargrrrÚ_is_incomplete_optionÔs
 
r›)r rrrDrc    CsÞd|d<|j|| ¡f|Ž}|j|j}|rÚ|j}t|tƒrÚ|js€| ||¡\}}}|dkr`|S|j|||dd}|j|j}qØ|}|rÄ| ||¡\}}}|dkr¦|S|j|||dddd}|j}q„|}|j|j•}q(qÚq(|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.
    TÚresilient_parsingN)ÚparentrœF)rZallow_extra_argsÚallow_interspersed_argsrœ)    Z make_contextÚcopyZprotected_argsrDÚcommandr‹rÚchainZresolve_command)    r rrrDrHr r(ÚcmdZsub_ctxrrrrFìs< 
úrF)rHrDrErcCs®|dkrd}n,d|kr:t||ƒr:| d¡\}}}| |¡d|krVt||ƒ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--)r”rÚappendr Ú
get_paramsr›r’)rHrDrEr(rrrŠrrrrG%s
 
 
rG)N)1rrr9Útypingr0rrÚcorerrrrrr    r
Úparserr Úutilsr rVr2r1rtrrrzr~r„r4r[r|rÚTypeVarÚTyper…r‡rXrUr3r‰rÚboolr’r”rZr›rFrYÚUnionrGrrrrÚ<module>sl          ú && ,j1ýÿþ 
    û :þ