o �J�h�M�@szUddlmZddlmZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd lmZdLdd�ZGdd�d�ZdZdZdZGdd�d�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�Zejd&d'd(�Zeeed)�Z d*e!d+< dMdNd/d0�Z"dOd3d4�Z#dPd7d8�Z$dQd>d?�Z%dRdAdB�Z&dSdDdE�Z'dTdFdG�Z(dUdJdK�Z)dS)V�)� annotationsN)�gettext�)�Argument)�Command)�Context)�Group)�Option)� Parameter)�ParameterSource)�echo�clir�ctx_args�cabc.MutableMapping[str, t.Any]� prog_name�str� complete_var� instruction�return�intc Csf|�d�\}}}t|�}|durdS|||||�}|dkr%t|���dS|dkr1t|���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�shellr�comp_cls�comp�r�TC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\click\shell_completion.py�shell_completes  r c@s.eZdZdZdZ  dddd�Zddd�ZdS)�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�plainNr#�t.Anyr$rr%� str | None�kwargsr�NonecK�||_||_||_||_dS�Nr")�selfr#r$r%r*rrr�__init__N� zCompletionItem.__init__�namecCs |j�|�Sr-)r&�get)r.r1rrr� __getattr__Zs zCompletionItem.__getattr__)r'N) r#r(r$rr%r)r*r(rr+)r1rrr()�__name__� __module__� __qualname__�__doc__� __slots__r/r3rrrrr!9s � 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@szeZdZUdZded< ded< d'dd�Zed(dd��Zd)dd�Zd(dd�Z d*dd�Z d+dd�Z d,d"d#�Z d(d$d%�Z d&S)-� 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 zt.ClassVar[str]r1�source_templater rrrrrrrr+cCr,r-)r rrr)r.r rrrrrrr/�r0zShellComplete.__init__cCs*tjdd|j�dd�tjd�}d|�d�S)zQThe name of the shell function defined by the completion script. z\W*��-r)�flagsZ _completion)�re�subr�replace�ASCII)r.Z safe_namerrr� func_name�s zShellComplete.func_name�dict[str, t.Any]cCs|j|j|jd�S)z�Vars for formatting :attr:`source_template`. By default this provides ``complete_func``, ``complete_var``, and ``prog_name``. )� complete_funcrr)rBrr�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`. )r:rFrErrrr�szShellComplete.source�tuple[list[str], str]cC�t�)z�Use the env vars defined by the shell script to return a tuple of ``args, incomplete``. This must be implemented by subclasses. ��NotImplementedErrorrErrr�get_completion_argssz!ShellComplete.get_completion_args�args� list[str]� incomplete�list[CompletionItem]cCs0t|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.rLrN�ctx�objrrr�get_completions s zShellComplete.get_completions�itemr!cCrH)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. rI�r.rUrrr�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)rW)�.0rUrErr� <listcomp>&sz*ShellComplete.complete.<locals>.<listcomp>� )rKrT�join)r.rLrN� completions�outrrErrs   zShellComplete.completeN) r rrrrrrrrr+�rr)rrC�rrG)rLrMrNrrrO�rUr!rr)r4r5r6r7�__annotations__r/�propertyrBrFrrKrTrWrrrrrr9�s        r9csLeZdZdZdZeZeddd��Zd�fdd � Z dd d �Z ddd�Z �Z S)� BashCompletezShell completion for Bash.�bashrr+cCs�ddl}ddl}|�d�}|durd}n|j|dddg|jd�}t�d|j���}|durM|� �\}}|dks?|dkrI|dkrKt t d �d d �dSdSdSt t d �d d �dS) Nrrdz--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� subprocess�which�run�PIPEr>�searchre�decode�groupsr r)rhriZbash_exe�match�output�major�minorrrr�_check_version0s0  � � ��  �zBashComplete._check_versionrcs|��t���Sr-)rt�superrrE�� __class__rrrQs zBashComplete.sourcerGcC�Xttjd�}ttjd�}|d|�}z ||}W||fSty+d}Y||fSw�N� COMP_WORDS� COMP_CWORDrr;��split_arg_string�os�environr� IndexError�r.�cwords�cwordrLrNrrrrKU�   ��z BashComplete.get_completion_argsrUr!cCs|j�d|j��S)N�,)r$r#rVrrrrWaszBashComplete.format_completion)rr+r^r_r`) r4r5r6r7r1� _SOURCE_BASHr:� staticmethodrtrrKrW� __classcell__rrrvrrc*s   rcc@�,eZdZdZdZeZd dd�Zdd d �Zd S)� ZshCompletezShell completion for Zsh.�zshrrGcCrxryr|r�rrrrKkr�zZshComplete.get_completion_argsrUr!rcCs(|j�d|j�d|jr|j��Sd��S)NrZr)r$r#r%rVrrrrWws(zZshComplete.format_completionNr_r`) r4r5r6r7r1� _SOURCE_ZSHr:rKrWrrrrr�e�   r�c@r�)� FishCompletezShell completion for Fish.�fishrrGcCsHttjd�}tjd}|dd�}|r |r |d|kr |��||fS)Nrzr{r�����)r}r~r�pop)r.r�rNrLrrrrK�s   z FishComplete.get_completion_argsrUr!rcCs2|jr|j�d|j�d|j��S|j�d|j��S)Nr�� )r%r$r#rVrrrrW�szFishComplete.format_completionNr_r`) r4r5r6r7r1� _SOURCE_FISHr:rKrWrrrrr�{r�r��ShellCompleteTypeztype[ShellComplete])�bound)rdr�r�zdict[str, type[ShellComplete]]�_available_shells�clsr1r)cCs|dur|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)r1r�)r�r1rrr�add_completion_class�s r�r�type[ShellComplete] | NonecCs 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�r2)rrrrr�s r�stringrMcCsbddl}|j|dd�}d|_d|_g}z |D]}|�|�qW|Sty0|�|j�Y|Sw)a�Split 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)�posixr;)�shlex�whitespace_split� commenters�append� ValueError�token)r�r��lexr]r�rrrr}�s � ��r}rRr�paramr �boolcCslt|t�sdS|jdusJ�|j�|j�}|jdkp5|�|j�tjup5|jdko5t|t t f�o5t |�|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) � isinstancerr1�paramsr2�nargs�get_parameter_sourcer � COMMANDLINE�tuple�list�len)rRr�r#rrr�_is_incomplete_argument�s  �  � �r�r#cCs|sdS|d}||jvS)z5Check if the value looks like the start of an option.Fr)� _opt_prefixes)rRr#�crrr�_start_of_option�s r�rLcCsjt|t�sdS|js |jrdSd}tt|��D]\}}|d|jkr$nt||�r+|}q|duo4||jvS)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�r �is_flag�count� enumerate�reversedr�r��opts)rRrLr�Z last_option�index�argrrr�_is_incomplete_options   �r�c Cs�d|d<|j||��fi|����}|j|j}|r�|j}t|t�r�|js\|�||�\}}}|dur:|Wd�S|j|||dd��}|}|j|j}Wd�n1sVwYnH|}|r�|�||�\}}}|durv|Wd�S|j|||dddd�� } | }|j}Wd�n1s�wY|s`|}g|j�|j�}nn|sWd�|SWd�|SWd�|S1s�wY|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��allow_extra_args�allow_interspersed_argsr�) � make_context�copy�_protected_argsrL�commandr�r�chain�resolve_command) r rrrLrRr�r1�cmd�sub_ctxZ sub_sub_ctxrrrrPsh  � �������� �+� �+� �+�+rPrN�tuple[Command | Parameter, str]cCs�|dkrd}nd|vrt||�r|�d�\}}}|�|�d|vr+t||�r+|j|fS|j�|�}|D]}t|||�rA||fSq3|D] }t||�rQ||fSqD|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. �=r;z--)r�rr�r�� get_paramsr�r�)rRrLrNr1rr�r�rrrrQXs"     �  � rQ) r rrrrrrrrrrrr-)r�r�r1r)rr�)rrrr�)r�rrrM)rRrr�r rr�)rRrr#rrr�)rRrrLrMr�r rr�) r rrrrrrLrMrr)rRrrLrMrNrrr�)*� __future__r�collections.abc�abc�cabcr~r>�typing�trr�corerrrrr r r �utilsr r r!r�r�r�r9rcr�r��TypeVarr�r�rar�rr}r�r�r�rPrQrrrr�<module>sJ           && ,h;� �  %  =
Memory