o
    j<f                     @  s  U d dl mZ d dlmZ 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dZejrfd dlmZ eddejdZnejdddZG dd deje Zd Zd!Zd"Zd#Z G d$d% d%ej!Z"G d&d' d'Z#G d(d) d)e#Z$G d*d+ d+e#Z%G d,d- d-e#Z&G d.d/ d/e#Z'e$e&e'e%d0Z(d1e)d2< ejd3d'd4Z*	dadbd9d:Z+ej,dcd>d?Z-ej,dddBd?Z-ej,dedEd?Z-ej,dfdGd?Z-dfdHd?Z-dgdKdLZ.dhdRdSZ/didUdVZ0djdXdYZ1dkdZd[Z2dld^d_Z3dS )m    )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t.Literal[0, 1]c           	      C  sr   | d\}}}t|}|du rdS || |||}|dkr)t|  dd dS |dkr7t|   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   sourceF)nlr   complete)	partitionget_completion_classr   r   encoder   )	r   r   r   r   r   shellr   comp_clscomp r    T/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/click/shell_completion.pyshell_complete   s   r"   )TypeVar
_ValueT_coT)	covariantdefault)r%   c                   @  s.   e Zd ZdZdZ		ddddZd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*   r   r+   
str | Nonekwargst.Anyr   Nonec                 K     || _ || _|| _|| _d S Nr(   )selfr)   r*   r+   r/   r    r    r!   __init__X      
zCompletionItem.__init__namec                 C  s   | j |S r3   )r,   get)r4   r7   r    r    r!   __getattr__d   s   zCompletionItem.__getattr__)r-   N)
r)   r$   r*   r   r+   r.   r/   r0   r   r1   )r7   r   r   r0   )__name__
__module____qualname____doc__	__slots__r5   r9   r    r    r    r!   r'   C   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)";
a  Register-ArgumentCompleter -Native -CommandName %(prog_name)s -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)

    $prev_complete = $env:%(complete_var)s
    $prev_words = $env:COMP_WORDS
    $prev_cword = $env:COMP_CWORD

    $env:%(complete_var)s = 'powershell_complete'
    $env:COMP_WORDS = $commandAst.ToString()
    if ($wordToComplete) {
        $env:COMP_CWORD = $commandAst.CommandElements.Count - 1
    } else {
        $env:COMP_CWORD = $commandAst.CommandElements.Count
    }

    try {
        $response = & %(prog_name)s 2>$null
    } finally {
        $env:%(complete_var)s = $prev_complete
        $env:COMP_WORDS = $prev_words
        $env:COMP_CWORD = $prev_cword
    }

    if (-not $response) { return }

    $prefix = "$wordToComplete*"
    $lines = $response -split "`n"
    for ($i = 0; $i + 2 -lt $lines.Count; $i += 3) {
        $type = $lines[$i]
        $value = $lines[$i + 1]
        $descr = $lines[$i + 2]
        if (-not $type) { continue }

        if ($type -eq 'plain') {
            $tip = if ($descr -and $descr -ne '_') { $descr } else { $value }
            [System.Management.Automation.CompletionResult]::new(
                $value, $value, 'ParameterValue', $tip)
        } elseif ($type -eq 'dir') {
            Get-ChildItem -Directory -Path $prefix -ErrorAction SilentlyContinue |
                ForEach-Object {
                    [System.Management.Automation.CompletionResult]::new(
                        $_.FullName, $_.Name, 'ProviderContainer', $_.FullName)
                }
        } elseif ($type -eq 'file') {
            Get-ChildItem -Path $prefix -ErrorAction SilentlyContinue |
                ForEach-Object {
                    $kind = 'ProviderItem'
                    if ($_.PSIsContainer) { $kind = 'ProviderContainer' }
                    [System.Management.Automation.CompletionResult]::new(
                        $_.FullName, $_.Name, $kind, $_.FullName)
                }
        }
    }
}
c                   @  s&   e Zd ZU ded< ded< ded< dS )_SourceVarsDictr   complete_funcr   r   N)r:   r;   r<   __annotations__r    r    r    r!   r?     s   
 r?   c                   @  s   e Zd ZU dZded< 	 ded< 	 ded< ded< d	ed
< d	ed< d'ddZed(ddZd)ddZd(ddZ	d*ddZ
d+dd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
    t.ClassVar[str]r7   source_templater   r   r   r   r   r   r   r   r1   c                 C  r2   r3   )r   r   r   r   )r4   r   r   r   r   r    r    r!   r5   3  r6   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   )flags_completion)resubr   replaceASCII)r4   	safe_namer    r    r!   	func_name?  s   zShellComplete.func_namer?   c                 C  s   | j | j| jdS )zVars for formatting :attr:`source_template`.

        By default this provides ``complete_func``, ``complete_var``,
        and ``prog_name``.
        )r@   r   r   )rN   r   r   r4   r    r    r!   source_varsG  s   zShellComplete.source_varsc                 C  s   | j |   S )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`.
        )rD   rP   rO   r    r    r!   r   S  s   zShellComplete.sourcetuple[list[str], str]c                 C     t )zUse the env vars defined by the shell script to return a
        tuple of ``args, incomplete``. This must be implemented by
        subclasses.
        NotImplementedErrorrO   r    r    r!   get_completion_args[  s   z!ShellComplete.get_completion_argsargs	list[str]
incompletelist[CompletionItem[str]]c                 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"   )r4   rV   rX   ctxobjr    r    r!   get_completionsb  s   
zShellComplete.get_completionsitemCompletionItem[str]c                 C  rR   )zFormat a completion item into the form recognized by the
        shell script. This must be implemented by subclasses.

        :param item: Completion item to format.
        rS   r4   r_   r    r    r!   format_completionp  s   zShellComplete.format_completionc                   s4      \}} ||} fdd|D }d|S )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.
        c                   s   g | ]}  |qS r    )rb   ).0r_   rO   r    r!   
<listcomp>  s    z*ShellComplete.complete.<locals>.<listcomp>
)rU   r^   join)r4   rV   rX   completionsoutr    rO   r!   r   x  s   
zShellComplete.completeN)
r   r   r   r   r   r   r   r   r   r1   r   r   )r   r?   r   rQ   )rV   rW   rX   r   r   rY   r_   r`   r   r   )r:   r;   r<   r=   rA   r5   propertyrN   rP   r   rU   r^   rb   r   r    r    r    r!   rB     s&   
 





rB   c                      s^   e Zd ZU dZdZded< eZded< eddd	Z	d fddZ
dddZdddZ  ZS )BashCompletezShell completion for Bash.bashrC   r7   rD   r   r1   c                  C  s   dd l } dd l}| d}|d u rd }n|j|dddg|jd}td|j }|d urM|	 \}}|dk s?|dkrI|dk rKt
td	d
d d S d S d S t
tdd
d d S )Nr   rn   z--norcz-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.)shutil
subprocesswhichrunPIPErI   searchro   decodegroupsr   r   )rr   rs   bash_exematchoutputmajorminorr    r    r!   _check_version  s0   


	
zBashComplete._check_versionr   c                   s   |    t  S r3   )r   superr   rO   	__class__r    r!   r     s   
zBashComplete.sourcerQ   c                 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   rE   split_arg_stringosenvironint
IndexErrorr4   cwordscwordrV   rX   r    r    r!   rU        
z BashComplete.get_completion_argsr_   CompletionItem[t.Any]c                 C  s   |j  d|j S )N,)r*   r)   ra   r    r    r!   rb     s   zBashComplete.format_completion)r   r1   ri   rj   )r_   r   r   r   )r:   r;   r<   r=   r7   rA   _SOURCE_BASHrD   staticmethodr   r   rU   rb   __classcell__r    r    r   r!   rm     s   
  
rm   c                   @  >   e Zd ZU dZdZded< eZded< ddd	ZdddZ	dS )ZshCompletezShell completion for Zsh.zshrC   r7   rD   r   rQ   c                 C  r   r   r   r   r    r    r!   rU     r   zZshComplete.get_completion_argsr_   r`   r   c                 C  s<   |j pd}|dkr|jddn|j}|j d| d| S )Nr   :z\:re   )r+   r)   rK   r*   )r4   r_   help_r)   r    r    r!   rb     s   
zZshComplete.format_completionNrj   rk   )
r:   r;   r<   r=   r7   rA   _SOURCE_ZSHrD   rU   rb   r    r    r    r!   r     s   
 
r   c                   @  r   )FishCompletezShell completion for Fish.fishrC   r7   rD   r   rQ   c                 C  sX   t tjd }tjd }|rt |d }|dd  }|r(|r(|d |kr(|  ||fS )Nr   r   r   r   )r   r   r   pop)r4   r   rX   rV   r    r    r!   rU     s   
z FishComplete.get_completion_argsr_   r`   r   c                 C  sF   |j r|j dddd}|j d|j d| S |j d|j S )z
        .. versionchanged:: 8.4.2
            Escape newlines and replace tabs with spaces in the help text to
            fix completion errors with multi-line help strings.
        re   z\n	 r   r+   rK   r*   r)   r4   r_   r   r    r    r!   rb     s   
zFishComplete.format_completionNrj   rk   )
r:   r;   r<   r=   r7   rA   _SOURCE_FISHrD   rU   rb   r    r    r    r!   r     s   
 
r   c                   @  r   )PowerShellCompletezhShell completion for PowerShell (Windows PowerShell 5.1+ and pwsh 7+).

    .. versionadded:: 8.5.0
    
powershellrC   r7   rD   r   rQ   c                 C  r   r   r   r   r    r    r!   rU     r   z&PowerShellComplete.get_completion_argsr_   r`   r   c                 C  s:   |j r|j dddd}nd}|j d|j d| S )Nr   re   r   r   r   r    r    r!   rb     s   z$PowerShellComplete.format_completionNrj   rk   )
r:   r;   r<   r=   r7   rA   _SOURCE_POWERSHELLrD   rU   rb   r    r    r    r!   r   	  s   
 
r   )rn   r   r   r   z't.Final[dict[str, type[ShellComplete]]]_available_shells_ShellCompleteT)boundclstype[_ShellCompleteT]r7   r.   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)r7   r   )r   r7   r    r    r!   add_completion_class5  s   r   r   t.Literal['bash']type[BashComplete]c                 C     d S r3   r    r   r    r    r!   r   I     r   t.Literal['fish']type[FishComplete]c                 C  r   r3   r    r   r    r    r!   r   K  r   t.Literal['zsh']type[ZshComplete]c                 C  r   r3   r    r   r    r    r!   r   M  r   type[ShellComplete] | Nonec                 C  r   r3   r    r   r    r    r!   r   O  r   c                 C  s
   t | 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.
    )r   r8   r   r    r    r!   r   Q  s   
stringrW   c                 C  sX   ddl }|j | dd}d|_d|_g }z|| W |S  ty+   ||j Y |S w )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``.
    r   NT)posixrE   )shlexwhitespace_split
commentersextend
ValueErrorappendtoken)r   r   lexrh   r    r    r!   r   [  s   r   r\   r   paramr
   boolc                 C  s^   t |tsdS | j|j}|jdkp.| |jtjup.|jdko.t |t	t
fo.t||jk S )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.
    Fr   r   )
isinstancer   paramsr8   r7   nargsget_parameter_sourcer   COMMANDLINEtuplelistlen)r\   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   )_opt_prefixes)r\   r)   cr    r    r!   _start_of_option  s   
r   rV   c                 C  sn   t |tsdS |js|jrdS d}tt|D ]\}}|d |jkr$ n
t| |r-|} nq|duo6||jv S )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   )	r   r	   is_flagcount	enumeratereversedr   r   opts)r\   rV   r   last_optionindexargr    r    r!   _is_incomplete_option  s   

r   c           
   	   C  s  d|d< | j || fi |}|j|j }|r|j}t|tr|js\|||\}}}|du r:|W  d   S |j |||dd}|}|j|j }W d   n1 sVw   Y  nH|}|r|||\}}}|du rv|W  d   S |j |||dddd}	|	}|j}W d   n1 sw   Y  |s`|}g |j|j}nn|sW d   |S W d   |S W d   |S 1 sw   Y  |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_argsrV   commandr   r   chainresolve_command)
r   r   r   rV   r\   r   r7   cmdsub_ctxsub_sub_ctxr    r    r!   rZ     sh   

+
+
++rZ   rX   tuple[Command | Parameter, str]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.
    =rE   z--)r   r   r   r   
get_paramsr   r   )r\   rV   rX   r7   r   r   r   r    r    r!   r[     s"   



r[   )r   r   r   r   r   r   r   r   r   r   r   r   r3   )r   r   r7   r.   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   rW   )r\   r   r   r
   r   r   )r\   r   r)   r   r   r   )r\   r   rV   rW   r   r
   r   r   )
r   r   r   r   r   r   rV   rW   r   r   )r\   r   rV   rW   rX   r   r   r   )4
__future__r   collections.abcabccabcr   rI   typingtr   r   corer   r   r   r   r	   r
   r   utilsr   r"   TYPE_CHECKINGtyping_extensionsr#   Anyr$   Genericr'   r   r   r   r   	TypedDictr?   rB   rm   r   r   r   r   rA   r   r   overloadr   r   r   r   r   rZ   r[   r    r    r    r!   <module>   sj    
'&&,:o;$%#



$

	
=