o
    ê}”eH  ã                   @   sB  U d dl Z d dlZd dlZd dlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dedejeejf dedededefdd„ZG dd„ dƒZdZdZdZG dd„ dƒZG dd„ deƒZG dd„ deƒZG d d!„ d!eƒZejd"ej e d#�Z!eeed$œZ"ej#eej e f e$d%< 	d<d&e!d'ej%e de!fd(d)„Z&d*edej%ej e  fd+d,„Z'd-e	d.ede(fd/d0„Z)d-e	d1ede(fd2d3„Z*d-e	d4ej+e d.ede(fd5d6„Z,dedejeejf ded4ej+e de	f
d7d8„Z-d-e	d4ej+e d9edej.ej/eef ef fd:d;„Z0dS )=é    N)Úgettexté   )ÚArgument)ÚBaseCommand)ÚContext)ÚMultiCommand)ÚOption)Ú	Parameter)ÚParameterSource)Úsplit_arg_string)ÚechoÚcliÚctx_argsÚ	prog_nameÚcomplete_varÚinstructionÚreturnc           	      C   sf   |  d¡\}}}t|ƒ}|du rdS || |||ƒ}|dkr%t| ¡ ƒ dS |dkr1t| ¡ ƒ dS dS )a   Perform 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   r   r   )	r   r   r   r   r   Úshellr   Zcomp_clsÚcomp© r   ú_/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/click/shell_completion.pyÚshell_complete   s   r   c                   @   sV   e Zd ZdZdZ		ddejdedeje dejd	df
d
d„Z	ded	ejfdd„Z
dS )Ú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   r    r!   Úkwargsr   c                 K   ó   || _ || _|| _|| _d S ©Nr   )Úselfr   r    r!   r$   r   r   r   Ú__init__L   ó   
zCompletionItem.__init__Únamec                 C   s   | j  |¡S r&   )r"   Úget)r'   r*   r   r   r   Ú__getattr__X   s   zCompletionItem.__getattr__)r#   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚtÚAnyÚstrÚOptionalr(   r,   r   r   r   r   r   7   s"    üþýüû
ú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
af  function %(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ö   e Zd ZU dZeje ed< 	 eje ed< 	 dedej	eej
f dededd	f
d
d„Zedefdd„ƒZdejeej
f fdd„Zdefdd„Zdejeje ef fdd„Zdeje dedeje fdd„Zdedefdd„Zdef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
    r*   Úsource_templater   r   r   r   r   Nc                 C   r%   r&   )r   r   r   r   )r'   r   r   r   r   r   r   r   r(   Ø   r)   zShellComplete.__init__c                 C   s*   t jdd| j dd¡t jd�}d|› d�S )zQThe name of the shell function defined by the completion
        script.
        z\W*Ú ú-r   )ÚflagsZ_completion)ÚreÚsubr   ÚreplaceÚASCII)r'   Ú	safe_namer   r   r   Ú	func_nameä   s   zShellComplete.func_namec                 C   s   | j | j| jdœS )z—Vars for formatting :attr:`source_template`.

        By default this provides ``complete_func``, ``complete_var``,
        and ``prog_name``.
        )Zcomplete_funcr   r   )r@   r   r   ©r'   r   r   r   Úsource_varsì   s   ýzShellComplete.source_varsc                 C   s   | 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`.
        )r7   rB   rA   r   r   r   r   ø   s   zShellComplete.sourcec                 C   ó   t ‚)z˜Use the env vars defined by the shell script to return a
        tuple of ``args, incomplete``. This must be implemented by
        subclasses.
        ©ÚNotImplementedErrorrA   r   r   r   Úget_completion_args   s   z!ShellComplete.get_completion_argsÚargsÚ
incompletec                 C   s0   t | j| j| j|ƒ}t|||ƒ\}}| ||¡S )aT  Determine 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   r   r   Ú_resolve_incompleter   )r'   rG   rH   ÚctxÚobjr   r   r   Úget_completions  s   
zShellComplete.get_completionsÚitemc                 C   rC   )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.
        rD   ©r'   rN   r   r   r   Úformat_completion  s   zShellComplete.format_completionc                    s4   ˆ   ¡ \}}ˆ  ||¡}‡ fdd„|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.
        c                    s   g | ]}ˆ   |¡‘qS r   )rP   )Ú.0rN   rA   r   r   Ú
<listcomp>&  s    z*ShellComplete.complete.<locals>.<listcomp>Ú
)rF   rM   Újoin)r'   rG   rH   ZcompletionsÚoutr   rA   r   r     s   
zShellComplete.complete)r-   r.   r/   r0   r2   ÚClassVarr4   Ú__annotations__r   ÚMutableMappingr3   r(   Úpropertyr@   ÚDictrB   r   ÚTupleÚListrF   r   rM   rP   r   r   r   r   r   r6   À   s>   
 þýüû
úÿÿ
þr6   c                       sl   e Zd ZdZdZeZeddd„ƒZde	f‡ fdd„Z
dejeje	 e	f fd	d
„Zdede	fdd„Z‡  ZS )ÚBashCompletezShell completion for Bash.Úbashr   Nc                  C   sŠ   dd l } | jg d¢| jd�}t d|j ¡ ¡}|d ur;| ¡ \}}|dk s-|dkr7|dk r9tt	dƒdd� d S d S d S tt	d	ƒdd� d S )
Nr   )r^   z-czecho "${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.)
Ú
subprocessÚrunÚPIPEr;   Úsearchr_   ÚdecodeÚgroupsr   r   )rb   ÚoutputÚmatchÚmajorÚminorr   r   r   Ú_check_version0  s&   
ÿÿ
ûÿ	
þzBashComplete._check_versionc                    s   |   ¡  tƒ  ¡ S r&   )rl   Úsuperr   rA   ©Ú	__class__r   r   r   J  s   
zBashComplete.sourcec                 C   óX   t tjd ƒ}ttjd ƒ}|d|… }z	|| }W ||fS  ty+   d}Y ||fS w ©NÚ
COMP_WORDSÚ
COMP_CWORDr   r8   ©r   ÚosÚenvironÚintÚ
IndexError©r'   ÚcwordsÚcwordrG   rH   r   r   r   rF   N  ó   
ýýz BashComplete.get_completion_argsrN   c                 C   s   |j › d|j› �S )Nú,)r    r   rO   r   r   r   rP   Z  s   zBashComplete.format_completion)r   N)r-   r.   r/   r0   r*   Ú_SOURCE_BASHr7   Ústaticmethodrl   r4   r   r2   r[   r\   rF   r   rP   Ú__classcell__r   r   rn   r   r]   *  s    r]   c                   @   óH   e Zd ZdZdZeZdejej	e
 e
f fdd„Zdede
fdd„Zd	S )
ÚZshCompletezShell completion for Zsh.Úzshr   c                 C   rp   rq   rt   ry   r   r   r   rF   d  r|   zZshComplete.get_completion_argsrN   c                 C   s(   |j › d|j› d|jr|j› �S d› �S )NrS   r   )r    r   r!   rO   r   r   r   rP   p  s   (zZshComplete.format_completionN)r-   r.   r/   r0   r*   Ú_SOURCE_ZSHr7   r2   r[   r\   r4   rF   r   rP   r   r   r   r   r‚   ^  ó    r‚   c                   @   r�   )
ÚFishCompletezShell completion for Fish.Úfishr   c                 C   sH   t tjd ƒ}tjd }|dd … }|r |r |d |kr | ¡  ||fS )Nrr   rs   r   éÿÿÿÿ)r   ru   rv   Úpop)r'   rz   rH   rG   r   r   r   rF   z  s   
z FishComplete.get_completion_argsrN   c                 C   s2   |j r|j› d|j› d|j › �S |j› d|j› �S )Nr}   ú	)r!   r    r   rO   r   r   r   rP   †  s   zFishComplete.format_completionN)r-   r.   r/   r0   r*   Ú_SOURCE_FISHr7   r2   r[   r\   r4   rF   r   rP   r   r   r   r   r†   t  r…   r†   ÚShellCompleteType)Úbound)r^   r‡   rƒ   Ú_available_shellsÚclsr*   c                 C   s   |du r| j }| t|< | S )am  Register 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*   r   r   r   Úadd_completion_class—  s   r�   r   c                 C   s
   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+   )r   r   r   r   r   «  s   
r   rK   Úparamc                 C   sl   t |tƒsdS |jdusJ ‚| j |j¡}|jdkp5|  |j¡tjup5|jdko5t |t	t
fƒo5t|ƒ|jk S )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   )Ú
isinstancer   r*   Úparamsr+   ÚnargsZget_parameter_sourcer
   ZCOMMANDLINEÚtupleÚlistÚlen)rK   r‘   r   r   r   r   Ú_is_incomplete_argumentµ  s   

ÿ
ÿúr˜   r   c                 C   s   |sdS |d }|| j v S )z5Check if the value looks like the start of an option.Fr   )Z_opt_prefixes)rK   r   Úcr   r   r   Ú_start_of_optionÎ  s   
rš   rG   c                 C   sj   t |tƒsdS |js|jrdS d}tt|ƒƒD ]\}}|d |jkr$ nt| |ƒr+|}q|duo4||jv S )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   Zis_flagÚcountÚ	enumerateÚreversedr”   rš   Úopts)rK   rG   r‘   Zlast_optionÚindexÚargr   r   r   Ú_is_incomplete_option×  s   

€r¡   c           	      C   sî   d|d< | j || ¡ fi |¤Ž}|j|j }|ru|j}t|tƒrp|jsB| ||¡\}}}|du r2|S |j |||dd�}|j|j }n1|}|re| ||¡\}}}|du rU|S |j |||dddd�}|j}|sF|}g |j¢|j¢}n	 |S |s|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£   Zallow_extra_argsÚallow_interspersed_argsr¢   )	Zmake_contextÚcopyZprotected_argsrG   Úcommandr’   r   ÚchainZresolve_command)	r   r   r   rG   rK   r¦   r*   ÚcmdZsub_ctxr   r   r   rI   ï  sB   
úòÜ$rI   rH   c                 C   s®   |dkrd}nd|v rt | |ƒr| d¡\}}}| |¡ d|vr+t | |ƒr+| j|fS | j | ¡}|D ]}t| ||ƒrA||f  S q3|D ]}t| |ƒrQ||f  S qD| j|fS )ah  Find 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.
    ú=r8   z--)rš   r   Úappendr¦   Ú
get_paramsr¡   r˜   )rK   rG   rH   r*   r   r“   r‘   r   r   r   rJ   (  s"   

ÿ
ÿ
rJ   r&   )1ru   r;   Útypingr2   r   r   Úcorer   r   r   r   r   r	   r
   Úparserr   Úutilsr   rX   r4   r3   rw   r   r   r~   r„   r‹   r6   r]   r‚   r†   ÚTypeVarÚTyperŒ   rŽ   rZ   rW   r5   r�   r   Úboolr˜   rš   r\   r¡   rI   r[   ÚUnionrJ   r   r   r   r   Ú<module>   sŽ   
 ÿþýüû
ú&& ,j4ýÿÿÿ
þ
 	ÿþýü
û9ÿÿÿþ