Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
shell_completion.cpython-313.pyc303 linesDownload Raw Back to __pycache__
1�

2�jR����%SSKJr SSKJr SSKrSSKrSSKrSSK	J	r3 SSKJr SSKJ
r
 SSKJr SSKJr SS	KJr SS4KJr SSKJr SSKJr S)S
jr"SS5rSrSrSr"SS5r"SS\5r"SS\5r"SS\5r\R<"SSS9r\\\S.r S\!S 'S*S+S!jjr"S,S"jr#S-S#jr$S.S$jr%S/S%jr&S0S&jr'S1S'jr(S2S(jr)g)3�)�annotationsN)�gettext�)�Argument)�Command)�Context)�Group)�Option)�	Parameter)�ParameterSource)�echoc���URS5upVn[U5nUcgU"XX#5nUS:Xa[UR55 gUS:Xa[UR	55 gg)a�Perform shell completion for the given CLI program.5 6:param cli: Command being called.7:param ctx_args: Extra arguments to pass to8    ``cli.make_context``.9:param prog_name: Name of the executable in the shell.10:param complete_var: Name of the environment variable that holds11    the completion instruction.12:param instruction: Value of ``complete_var`` with the completion13    instruction and shell, in the form ``instruction_shell``.14:return: Status code to exit with.15�_r�sourcer�complete)�	partition�get_completion_classr
rr)	�cli�ctx_args�	prog_name�complete_var�instruction�shellr�comp_cls�comps	         �\D:\code\apps\devtools\python\user_packages\Python313\site-packages\click/shell_completion.py�shell_completersm��&(�1�1�#�6��E�k�#�E�*�H�����C�9�;�D��h���T�[�[�]����j� ��T�]�]�_����c�J�\rSrSrSrSrSS	SjjrS16SjrSrg)�CompletionItem�9a�Represents a completion value and metadata about the value. The17default metadata is ``type`` to indicate special shell handling,18and ``help`` if a shell supports showing a help string next to the19value.20 21Arbitrary parameters can be passed when creating the object, and22accessed using ``item.attr``. If an attribute wasn't passed,23accessing it returns ``None``.24 25:param value: The completion suggestion.26:param type: Tells the shell script to provide special completion27    support for the type. Click uses ``"dir"`` and ``"file"``.28:param help: String shown next to the value if supported.29:param kwargs: Arbitrary metadata. The built-in implementations30    don't use this, but custom type completions paired with custom31    shell support could use it.32��value�type�help�_infoNc�4�XlX lX0lX@lg�Nr")�selfr#r$r%�kwargss     r�__init__�CompletionItem.__init__Ns��"�33��	� $�	��34rc�8�URRU5$r()r&�get)r)�names  r�__getattr__�CompletionItem.__getattr__Zs���z�z�~�~�d�#�#r)r&r%r$r#)�plainN)35r#�t.Anyr$�strr%�36str | Noner*r3�return�None)r/r4r6r3)	�__name__�37__module__�__qualname__�__firstlineno__�__doc__�	__slots__r+r0�__static_attributes__�rrr r 9sP���$3�I�38��	39��40��41��	42�43�44�45�
46�$rr a�%(complete_func)s() {47    local IFS=$'\n'48    local response49 50    response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD %(complete_var)s=bash_complete $1)51 52    for completion in $response; do53        IFS=',' read type value <<< "$completion"54 55        if [[ $type == 'dir' ]]; then56            COMPREPLY=()57            compopt -o dirnames58        elif [[ $type == 'file' ]]; then59            COMPREPLY=()60            compopt -o default61        elif [[ $type == 'plain' ]]; then62            COMPREPLY+=($value)63        fi64    done65 66    return 067}68 69%(complete_func)s_setup() {70    complete -o nosort -F %(complete_func)s %(prog_name)s71}72 73%(complete_func)s_setup;74a�#compdef %(prog_name)s75 76%(complete_func)s() {77    local -a completions78    local -a completions_with_descriptions79    local -a response80    (( ! $+commands[%(prog_name)s] )) && return 181 82    response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) %(complete_var)s=zsh_complete %(prog_name)s)}")83 84    for type key descr in ${response}; do85        if [[ "$type" == "plain" ]]; then86            if [[ "$descr" == "_" ]]; then87                completions+=("$key")88            else89                completions_with_descriptions+=("$key":"$descr")90            fi91        elif [[ "$type" == "dir" ]]; then92            _path_files -/93        elif [[ "$type" == "file" ]]; then94            _path_files -f95        fi96    done97 98    if [ -n "$completions_with_descriptions" ]; then99        _describe -V unsorted completions_with_descriptions -U100    fi101 102    if [ -n "$completions" ]; then103        compadd -U -V unsorted -a completions104    fi105}106 107if [[ $zsh_eval_context[-1] == loadautofunc ]]; then108    # autoload from fpath, call function directly109    %(complete_func)s "$@"110else111    # eval/source/. command, register function for later112    compdef %(complete_func)s %(prog_name)s113fi114affunction %(complete_func)s;115    set -l response (env %(complete_var)s=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(prog_name)s);116 117    for completion in $response;118        set -l metadata (string split "," $completion);119 120        if test $metadata[1] = "dir";121            __fish_complete_directories $metadata[2];122        else if test $metadata[1] = "file";123            __fish_complete_path $metadata[2];124        else if test $metadata[1] = "plain";125            echo $metadata[2];126        end;127    end;128end;129 130complete --no-files --command %(prog_name)s --arguments "(%(complete_func)s)";131c��\rSrSr%SrS\S'S\S'SSjr\SSj5rSSjr	SS	jr132SS133jrSSjrSSjr
SS
jrSrg)�
ShellComplete��a�Base class for providing shell completion support. A subclass for134a given shell will override attributes and methods to implement the135completion instructions (``source`` and ``complete``).136 137:param cli: Command being called.138:param prog_name: Name of the executable in the shell.139:param complete_var: Name of the environment variable that holds140    the completion instruction.141 142.. versionadded:: 8.0143zt.ClassVar[str]r/�source_templatec�4�XlX lX0lX@lgr()rrrr)r)rrrrs     rr+�ShellComplete.__init__�s���� �
�"��(�rc��[R"SSURRSS5[RS9nSUS3$)zAThe name of the shell function defined by the completion144script.145z\W*��-r)�flags�_completion)�re�subr�replace�ASCII)r)�	safe_names  r�	func_name�ShellComplete.func_name�s<��146�F�F�6�2�t�~�~�'=�'=�c�3�'G�r�x�x�X�	��9�+�[�)�)rc�J�URURURS.$)zVars for formatting :attr:`source_template`.147 148By default this provides ``complete_func``, ``complete_var``,149and ``prog_name``.150)�
complete_funcrr)rPrr�r)s r�source_vars�ShellComplete.source_vars�s%��"�^�^� �-�-����151�	152rc�<�URUR5-$)z�Produce the shell script that defines the completion153function. By default this ``%``-style formats154:attr:`source_template` with the dict returned by155:meth:`source_vars`.156)rCrUrTs rr�ShellComplete.sources���#�#�d�&6�&6�&8�8�8rc��[e)z�Use the env vars defined by the shell script to return a157tuple of ``args, incomplete``. This must be implemented by158subclasses.159��NotImplementedErrorrTs r�get_completion_args�!ShellComplete.get_completion_argss160��161"�!rc��[URURURU5n[	X1U5upBURX25$)a,Determine the context and last complete command or parameter162from the complete args. Call that object's ``shell_complete``163method to get the completions for the incomplete value.164 165:param args: List of complete args before the incomplete value.166:param incomplete: Value being completed. May be empty.167)�_resolve_contextrrr�_resolve_incompleter)r)�args�168incomplete�ctx�objs     r�get_completions�ShellComplete.get_completionss?���t�x�x��������M��-�c��D����!�!�#�2�2rc��[e)z�Format a completion item into the form recognized by the169shell script. This must be implemented by subclasses.170 171:param item: Completion item to format.172rZ�r)�items  r�format_completion�ShellComplete.format_completions173��"�!rc��UR5upURX5nUVs/sHo@RU5PM nnSRU5$s snf)z�Produce the completion data to send back to the shell.174 175By default this calls :meth:`get_completion_args`, gets the176completions, then calls :meth:`format_completion` for each177completion.178�179)r\rerj�join)r)rarb�completionsri�outs      rr�ShellComplete.complete#sV�� �3�3�5����*�*�4�<��8C�D���%�%�d�+���D��y�y��~���Es�A)rrrrN)180rrr�cabc.MutableMapping[str, t.Any]rr4rr4r6r7�r6r4)r6zdict[str, t.Any]�r6ztuple[list[str], str])ra�	list[str]rbr4r6zlist[CompletionItem]�rir r6r4)r8r9r:r;r<�__annotations__r+�propertyrPrUrr\rerjrr>r?rrrArA�s���181����182%�$��183)�
�184)�2�185)��	186)�187�188)�189�
190)��*��*�191192�9�"�1933�"�194rrAc�`^�\rSrSrSrSr\r\S	Sj5r	S195U4Sjjr196SSjrSSjrSr
U=r$)
�BashCompletei0zShell completion for Bash.�bashc�|�SSKnSSKnURS5nUcSnOMURUSSS/URS9n[197R"SURR55nUb:UR5upVUS:dUS:XaUS:a[[S	5S198S9 ggg[[S5S199S9 g)
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�200subprocess�which�run�PIPErK�searchr}�decode�groupsr
r)r�r��bash_exe�match�output�major�minors       r�_check_version�BashComplete._check_version6s������<�<��'�����E��^�^��8�T�+C�D�!���$��F��I�I�3�V�]�]�5I�5I�5K�L�E��� �<�<�>�L�E��s�{�e�s�l�u�s�{���4����0;�l�
��T�U��
rc�@>�UR5 [TU]	5$r()r��superr)r)�	__class__s �rr�BashComplete.sourceWs��������w�~��rc��[[RS5n[[RS5nUSUnXnX44$![a SnX44$f=f�N�201COMP_WORDS�202COMP_CWORDrrG��split_arg_string�os�environ�int�203IndexError�r)�cwords�cwordrarbs     rr\� BashComplete.get_completion_args[�i��!�"�*�*�\�":�;���B�J�J�|�,�-���a����	���J������	��J����	���A�A�Ac�8�URSUR3$)N�,)r$r#rhs  rrj�BashComplete.format_completiongs���)�)��A�d�j�j�\�*�*rr?)r6r7rsrtrv)r8r9r:r;r<r/�_SOURCE_BASHrC�staticmethodr�rr\rjr>�
__classcell__)r�s@rrzrz0s7���$��D�"�O�����@ �204 �+�+rrzc�4�\rSrSrSrSr\rSSjrS	Sjr	Sr205g)206�ZshCompleteikzShell completion for Zsh.�zshc��[[RS5n[[RS5nUSUnXnX44$![a SnX44$f=fr�r�r�s     rr\�ZshComplete.get_completion_argsqr�r�c��UR=(d SnUS:waURRSS5OURnURSUSU3$)Nr�:z\:rm)r%r#rMr$)r)ri�help_r#s    rrj�ZshComplete.format_completion}sO���	�	� �S��38�3�,��207�208�"�"�3��.�D�J�J���)�)��B�u�g�R��w�/�/rr?Nrtrv)r8r9r:r;r<r/�_SOURCE_ZSHrCr\rjr>r?rrr�r�ks��#��D�!�O�209 �0rr�c�4�\rSrSrSrSr\rSSjrS	Sjr	Sr210g)211�FishCompletei�zShell completion for Fish.�fishc���[[RS5n[RSnU(a[U5SnUSSnU(a U(aUSU:XaUR5 X24$)Nr�r�rr�����)r�r�r��pop)r)r�rbras    rr\� FishComplete.get_completion_args�sd��!�"�*�*�\�":�;���Z�Z��-�212��)�*�5�a�8�J��a�b�z���$�4��8�z�#9��H�H�J���rc��UR(a(URSURSUR3$URSUR3$)Nr��	)r%r$r#rhs  rrj�FishComplete.format_completion�sE���9�9��i�i�[��$�*�*��R��	�	�{�;�;��)�)��A�d�j�j�\�*�*rr?Nrtrv)r8r9r:r;r<r/�_SOURCE_FISHrCr\rjr>r?rrr�r��s��$��D�"�O� �+rr��ShellCompleteTypeztype[ShellComplete])�bound)r{r�r�zdict[str, type[ShellComplete]]�_available_shellsc�6�UcURnU[U'U$)aQRegister a :class:`ShellComplete` subclass under the given name.213The name will be provided by the completion instruction environment214variable during completion.215 216:param cls: The completion class that will handle completion for the217    shell.218:param name: Name to register the class under. Defaults to the219    class's ``name`` attribute.220)r/r�)�clsr/s  r�add_completion_classr��s"���|��x�x��!��d���Jrc�,�[RU5$)z�Look up a registered :class:`ShellComplete` subclass by the name221provided by the completion instruction environment variable. If the222name isn't registered, returns ``None``.223 224:param shell: Name the class is registered under.225)r�r.)rs rrr�s��� � ��'�'rc���SSKnURUSS9nSUlSUl/nUHnURU5 M U$![a URUR2265 U$f=f)a�Split an argument string as with :func:`shlex.split`, but don't227fail if the string is incomplete. Ignores a missing closing quote or228incomplete escape sequence and uses the partial token as-is.229 230.. code-block:: python231 232    split_arg_string("example 'my file")233    ["example", "my file"]234 235    split_arg_string("example my\")236    ["example", "my"]237 238:param string: String to split.239 240.. versionchanged:: 8.2241    Moved to ``shell_completion`` from ``parser``.242rNT)�posixrG)�shlex�whitespace_split�243commenters�append�244ValueError�token)�stringr��lexrpr�s     rr�r��sw��$�245�+�+�f�D�+�246)�C��C���C�N�247�C���E��J�J�u����J��
��	�248�249�3�9�9���J�
�s�A�%A+�*A+c��[U[5(dgURceURR	UR5nUR250S:H=(d} UR
UR5[RL=(dK UR251S:�=(a5 [U[[45=(a [U5UR252:$)z�Determine if the given parameter is an argument that can still253accept values.254 255:param ctx: Invocation context for the command represented by the256    parsed complete args.257:param param: Argument object being checked.258Fr�r)�259isinstancerr/�paramsr.�nargs�get_parameter_sourcer�COMMANDLINE�tuple�list�len)rc�paramr#s   r�_is_incomplete_argumentr��s����e�X�&�&���:�:�!�!�!��J�J�N�N�5�:�:�&�E�
���r��	260��#�#�E�J�J�/��7R�7R�R�	261�
�K�K�!�O�
)��5�5�$�-�0�
)��E�262�U�[�[�(�
rc�8�U(dgUSnX R;$)z5Check if the value looks like the start of an option.Fr)�
_opt_prefixes)rcr#�cs   r�_start_of_optionr�s ����
�a��A��!�!�!�!rc�6�[U[5(dgUR(dUR(agSn[	[U55H.upEUS-UR:�a O[X5(dM,Un O USL=(a X2R;$)z�Determine if the given parameter is an option that needs a value.263 264:param args: List of complete args before the incomplete value.265:param param: Option object being checked.266FNr)	r�r267�is_flag�count�	enumerate�reversedr�r��opts)rcrar��last_option�index�args      r�_is_incomplete_optionr�s}���e�V�$�$���}�}������K�����/�268���1�9�u�{�{�"���C�%�%��K��
0��d�"�@�{�j�j�'@�@rc269�0�SUS'UR"X#R540UD6nURUR-nU(GaURn[U[5(a�UR(dXURXC5upgnUcUsSSS5 $URXcUSS9nUnURUR-nSSS5 O}UnU(aVURXC5upgnUcUsSSS5 $URUUUSSSS9n	U	nURnSSS5 U(aMVUn/URQURQnOO270U(aGMSSS5 U$!,(df   N"=f!,(df   NZ=f!,(df   W$=f)aHProduce the context hierarchy starting with the command and271traversing the complete arguments. This only follows the commands,272it doesn't trigger input prompts or callbacks.273 274:param cli: Command being called.275:param prog_name: Name of the executable in the shell.276:param args: List of complete args before the incomplete value.277T�resilient_parsingN)�parentr�F)r��allow_extra_args�allow_interspersed_argsr�)	�make_context�copy�_protected_argsra�commandr�r	�chain�resolve_command)278rrrrarcr�r/�cmd�sub_ctx�sub_sub_ctxs279          rr_r_2s���%)�H�
 �!�	�	�	�)�Y�Y�[�	=�H�	=���"�"�S�X�X�-����k�k�G��'�5�)�)��}�}�&-�&=�&=�c�&H�O�D�t��{�"�280>�	=��)�)��3�$�*�� �%��"�2�2�S�X�X�=��	��"�G��*1�*A�*A�#�*L���4��;�#&�3281>�	=�6!�-�-� � �#&�-1�49�.2�
.��)�&1�G�#*�<�<�D��
�$�""�C�D�W�4�4�D�w�|�|�D�D��M�d�282>�V�J�=������7283>�	=�V�J�sN�A,F�F�.E$�284*F�>F�E5�!F�2%F�$285E2	�.F�5286F	�?F�287Fc��US:XaSnO;SU;a5[X5(a%URS5up4nURU5 SU;a[X5(aURU4$URR	U5nUHn[XU5(dMXb4s $ UHn[
X5(dMXb4s $ URU4$)aPFind the Click object that will handle the completion of the288incomplete value. Return the object and the incomplete value.289 290:param ctx: Invocation context for the command represented by291    the parsed complete args.292:param args: List of complete args before the incomplete value.293:param incomplete: Value being completed. May be empty.294�=rGz--)r�rr�r��295get_paramsr�r�)rcrarbr/rr�r�s       rr`r`os����S���296�	�297�	�/��@�@�(�2�2�3�7�������D���4��,�S�=�=��{�{�J�&�&�
�[�[�
#�
#�C�
(�F��� ��E�2�2��$�$����"�3�.�.��$�$���;�;�298�"�"r)rrrrrrr4rr4rr4r6r�r()r�r�r/r5r6r�)rr4r6ztype[ShellComplete] | None)r�r4r6ru)rcrr�rr6�bool)rcrr#r4r6r�)rcrrarur�rr6r�)299rrrrrrr4rarur6r)rcrrarurbr4r6ztuple[Command | Parameter, str])*�300__future__r�collections.abc�abc�cabcr�rK�typing�trr�corerrrr	r301rr�utilsr
rr r�r�r�rArzr�r��TypeVarr�r�rwr�rr�r�r�r�r_r`r?rr�<module>rs���"��	�	�� �������!��#
�	�#
�-�#
��#
��	#
�302�#
�	�
#
�L"$�"$�L��L*��X��.e�e�P8+�=�8+�v!0�-�!0�H+�=�+�6�I�I�1�9N�O��
���5��1��04��	��",����((�"�J�2"�A�2:�	�:�-�:��:��	:�303
�:�z,#�	�,#�!�,#�/2�,#�$�,#r
codekingpro/portable-devtools · Team Ai