
    GjZX                    >   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 	 	 	 	 	 	 	 	 	 	 	 	 d3dZej,                  rd dlmZ  eddej2                        Zn ej0                  dd      Z G d dej6                  e         ZdZdZdZ G d dej@                        Z! G d d      Z" G d de"      Z# G d de"      Z$ G d  d!e"      Z%e#e%e$d"Z&d#e'd$<    ej0                  d%d&      Z(	 d4	 	 	 	 	 d5d'Z)ejT                  d6d(       Z+ejT                  d7d)       Z+ejT                  d8d*       Z+ejT                  d9d+       Z+d9d,Z+d:d-Z,d;d.Z-d<d/Z.d=d0Z/	 	 	 	 	 	 	 	 	 	 d>d1Z0	 	 	 	 	 	 	 	 d?d2Z1y)@    )annotationsN)gettext   )Argument)Command)Context)Group)Option)	Parameter)ParameterSource)echoc                   |j                  d      \  }}}t        |      }|y || |||      }|dk(  r*t        |j                         j	                         d       y|dk(  r(t        |j                         j	                                yy)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.
    _r   sourceF)nlr   complete)	partitionget_completion_classr   r   encoder   )	clictx_args	prog_namecomplete_varinstructionshellr   comp_clscomps	            \/var/www/python/quitsure-support/venv/lib/python3.12/site-packages/click/shell_completion.pyshell_completer      s    & (11#6E1k#E*HC9l;D hT[[]!!#.j T]]_##%&    )TypeVar
_ValueT_coT)	covariantdefault)r#   c                  <    e Zd ZdZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZddZy)	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_infoNc                <    || _         || _        || _        || _        y Nr'   )selfr(   r)   r*   kwargss        r   __init__zCompletionItem.__init__X   s      "'
	 $	
r    c                8    | j                   j                  |      S r-   )r+   get)r.   names     r   __getattr__zCompletionItem.__getattr__d   s    zz~~d##r    )plainN)
r(   r"   r)   strr*   
str | Noner/   t.AnyreturnNone)r3   r6   r9   r8   )__name__
__module____qualname____doc__	__slots__r0   r4    r    r   r&   r&   C   sP    $ 3I
 	

 
 	

 
 

$r    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                  ,    e Zd ZU ded<   ded<   ded<   y)_SourceVarsDictr6   complete_funcr   r   N)r;   r<   r=   __annotations__r@   r    r   rB   rB      s    Nr    rB   c                      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Zedd       ZddZddZ	ddZ
	 	 	 	 	 	 ddZddZddZy)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]r3   source_templater   r   cabc.MutableMapping[str, t.Any]r   r6   r   r   c                <    || _         || _        || _        || _        y r-   )r   r   r   r   )r.   r   r   r   r   s        r   r0   zShellComplete.__init__   s!      "(r    c                    t        j                  dd| j                  j                  dd      t         j                        }d| dS )zQThe name of the shell function defined by the completion
        script.
        z\W* -r   )flags_completion)resubr   replaceASCII)r.   	safe_names     r   	func_namezShellComplete.func_name  s<    
 FF62t~~'='=c3'GrxxX	9+[))r    c                J    | j                   | j                  | j                  dS )zVars for formatting :attr:`source_template`.

        By default this provides ``complete_func``, ``complete_var``,
        and ``prog_name``.
        )rC   r   r   )rU   r   r   r.   s    r   source_varszShellComplete.source_vars	  s%     "^^ --
 	
r    c                <    | j                   | j                         z  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`.
        )rH   rX   rW   s    r   r   zShellComplete.source  s     ##d&6&6&888r    c                    t         )zUse the env vars defined by the shell script to return a
        tuple of ``args, incomplete``. This must be implemented by
        subclasses.
        NotImplementedErrorrW   s    r   get_completion_argsz!ShellComplete.get_completion_args  s
    
 "!r    c                    t        | j                  | j                  | j                  |      }t	        |||      \  }}|j                  ||      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.   args
incompletectxobjs        r   get_completionszShellComplete.get_completions$  sE     txxM-c4DZ!!#z22r    c                    t         )zFormat a completion item into the form recognized by the
        shell script. This must be implemented by subclasses.

        :param item: Completion item to format.
        r[   r.   items     r   format_completionzShellComplete.format_completion2  s
     "!r    c                    | j                         \  }}| j                  ||      }|D cg c]  }| j                  |       }}dj                  |      S c c}w )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.
        
)r]   re   ri   join)r.   ra   rb   completionsrh   outs         r   r   zShellComplete.complete:  s[      335j**4<8CDt%%d+DDyy~ Es   AN)
r   r   r   rI   r   r6   r   r6   r9   r:   r9   r6   )r9   rB   r9   ztuple[list[str], str])ra   	list[str]rb   r6   r9   zlist[CompletionItem[str]]rh   zCompletionItem[str]r9   r6   )r;   r<   r=   r>   rD   r0   propertyrU   rX   r   r]   re   ri   r   r@   r    r   rF   rF      s    
 
 %$ 
L--N
)
) 2
) 	
)
 
) 

) * *

9"33+.3	"3"
r    rF   c                  d     e Zd ZU dZdZded<   eZded<   ed
d       Z	d fdZ
ddZdd	Z xZS )BashCompletezShell completion for Bash.bashrG   r3   rH   c                    dd l } dd l}| j                  d      }|d }nO|j                  |dddg|j                        }t        j                  d|j                  j                               }|;|j                         \  }}|dk  s
|dk(  r|dk  rt        t        d	      d
       y y y t        t        d      d
       y )Nr   rv   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PIPErP   searchrx   decodegroupsr   r   )r{   r|   bash_exematchoutputmajorminors          r   _check_versionzBashComplete._check_versionM  s    <<'E^^8T+CD! $ F II3V]]5I5I5KLE <<>LE5s{eslus{4  0;l TUr    c                @    | j                          t        | 	         S r-   )r   superr   )r.   	__class__s    r   r   zBashComplete.sourcen  s    w~r    c                    t        t        j                  d         }t        t        j                  d         }|d| }	 ||   }||fS # t        $ r d}Y ||fS w xY wN
COMP_WORDS
COMP_CWORDr   rL   split_arg_stringosenvironint
IndexErrorr.   cwordscwordra   rb   s        r   r]   z BashComplete.get_completion_argsr  o    !"**\":;BJJ|,-a	J Z  	JZ	   A AAc                8    |j                    d|j                   S )N,)r)   r(   rg   s     r   ri   zBashComplete.format_completion~  s    ))Adjj\**r    )r9   r:   ro   rp   )rh   zCompletionItem[t.Any]r9   r6   )r;   r<   r=   r>   r3   rD   _SOURCE_BASHrH   staticmethodr   r   r]   ri   __classcell__)r   s   @r   ru   ru   G  s<    $"D/"'3O_3 @ 
 +r    ru   c                  >    e Zd ZU dZdZded<   eZded<   d	dZd
dZ	y)ZshCompletezShell completion for Zsh.zshrG   r3   rH   c                    t        t        j                  d         }t        t        j                  d         }|d| }	 ||   }||fS # t        $ r d}Y ||fS w xY wr   r   r   s        r   r]   zZshComplete.get_completion_args  r   r   c                    |j                   xs d}|dk7  r|j                  j                  dd      n|j                  }|j                   d| d| S )Nr   :z\:rk   )r*   r(   rR   r)   )r.   rh   help_r(   s       r   ri   zZshComplete.format_completion  sO    		 S 383,

""3.DJJ))BugRw//r    Nrp   rr   )
r;   r<   r=   r>   r3   rD   _SOURCE_ZSHrH   r]   ri   r@   r    r   r   r     s#    #!D/!'2O_2
 0r    r   c                  >    e Zd ZU dZdZded<   eZded<   d	dZd
dZ	y)FishCompletezShell completion for Fish.fishrG   r3   rH   c                    t        t        j                  d         }t        j                  d   }|rt        |      d   }|dd  }|r|r|d   |k(  r|j                          ||fS )Nr   r   r   r   )r   r   r   pop)r.   r   rb   ra   s       r   r]   z FishComplete.get_completion_args  sf    !"**\":;ZZ-
)*5a8Jabz $48z#9HHJZr    c                    |j                   rJ|j                   j                  dd      j                  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.
        rk   z\n	 r   )r*   rR   r)   r(   )r.   rh   r   s      r   ri   zFishComplete.format_completion  sf     99II%%dE2::4EEii[$**Rw77))Adjj\**r    Nrp   rr   )
r;   r<   r=   r>   r3   rD   _SOURCE_FISHrH   r]   ri   r@   r    r   r   r     s#    $"D/"'3O_3 +r    r   )rv   r   r   z't.Final[dict[str, type[ShellComplete]]]_available_shells_ShellCompleteT)boundc                4    || 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.
    )r3   r   )clsr3   s     r   add_completion_classr     s"     |xx!dJr    c                     y r-   r@   r   s    r   r   r         JMr    c                     y r-   r@   r   s    r   r   r     r   r    c                     y r-   r@   r   s    r   r   r     s    HKr    c                     y r-   r@   r   s    r   r   r     s    DGr    c                ,    t         j                  |       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   r2   r   s    r   r   r     s       ''r    c                    ddl }|j                  | d      }d|_        d|_        g }	 |D ]  }|j                  |        	 |S # t        $ r |j                  |j
                         Y |S w xY 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)posixrL   )shlexwhitespace_split
commentersappend
ValueErrortoken)stringr   lexrn   r   s        r   r   r     s|    $ 
++fD+
)CCCN
C 	EJJu	 J   	

399Js   A $A,+A,c                l   t        |t              sy| j                  j                  |j                        }|j
                  dk(  xsn | j                  |j                        t        j                  uxsA |j
                  dkD  xr0 t        |t        t        f      xr 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   paramsr2   r3   nargsget_parameter_sourcer   COMMANDLINEtuplelistlen)rc   paramr(   s      r   _is_incomplete_argumentr     s     eX&JJNN5::&Er 	
##EJJ/7R7RR	
 KK!O )55$-0)E
U[[(r    c                .    |sy|d   }|| j                   v S )z5Check if the value looks like the start of an option.Fr   )_opt_prefixes)rc   r(   cs      r   _start_of_optionr   6  s"    aA!!!!r    c                   t        |t              sy|j                  s|j                  ryd}t	        t        |            D ])  \  }}|dz   |j                  kD  r nt        | |      s'|} n |duxr ||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)rc   ra   r   last_optionindexargs         r   _is_incomplete_optionr   ?  s     eV$}}K/ 
s19u{{"C%K d"@{ejj'@@r    c           	        d|d<    | j                   ||j                         fi |5 }|j                  |j                  z   }|r|j                  }t        |t              r|j                  s]|j                  ||      \  }}}||cddd       S |j                  |||d      5 }|}|j                  |j                  z   }ddd       nv|}|rT|j                  ||      \  }}}||cddd       S |j                  |||ddd      5 }	|	}|j                  }ddd       |rT|}g |j                  |j                  }nn|rddd       |S # 1 sw Y   xY w# 1 sw Y   CxY w# 1 sw Y   S xY w)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_argsra   commandr   r	   chainresolve_command)
r   r   r   ra   rc   r   r3   cmdsub_ctxsub_sub_ctxs
             r   r_   r_   X  s    %)H !			)TYY[	=H	= )""SXX-kkG'5)}}&-&=&=c4&HOD#t{") ) ))d3$ *  > %"22SXX=	> > "G*1*A*A#t*Lc4;#&3) )6 !--  #&-149.2 .  	0 )&1G#*<<D	0 " "CDW44Dw||DDM )V J=> >	0 	07)V JsN   AE$E$$E &E$0E$E
E$! E$E	E$E!	E$$E.c                r   |dk(  rd}n6d|v r2t        | |      r&|j                  d      \  }}}|j                  |       d|vrt        | |      r| j                  |fS | j                  j	                  |       }|D ]  }t        | ||      s||fc S  |D ]  }t        | |      s||fc S  | 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.
    =rL   z--)r   r   r   r   
get_paramsr   r   )rc   ra   rb   r3   r   r   r   s          r   r`   r`     s     S
	
	/Z@(2237aD 4,S*={{J&&[[##C(F  % dE2*$$%  %"3.*$$% ;;
""r    )r   r   r   rI   r   r6   r   r6   r   r6   r9   zt.Literal[0, 1]r-   )r   type[_ShellCompleteT]r3   r7   r9   r   )r   zt.Literal['bash']r9   ztype[BashComplete])r   zt.Literal['fish']r9   ztype[FishComplete])r   zt.Literal['zsh']r9   ztype[ZshComplete])r   r6   r9   ztype[ShellComplete] | None)r   r6   r9   rq   )rc   r   r   r   r9   bool)rc   r   r(   r6   r9   r   )rc   r   ra   rq   r   r   r9   r   )
r   r   r   rI   r   r6   ra   rq   r9   r   )rc   r   ra   rq   rb   r6   r9   ztuple[Command | Parameter, str])2
__future__r   collections.abcabccabcr   rP   typingtr   r   corer   r   r   r	   r
   r   r   utilsr   r   TYPE_CHECKINGtyping_extensionsr!   Anyr"   Genericr&   r   r   r   	TypedDictrB   rF   ru   r   r   r   rD   r   r   overloadr   r   r   r   r   r_   r`   r@   r    r   <module>r     s    "  	 	          ! $	$-$ $ 	$
 $ $N ??) quuEJ<48J"$QYYz* "$LL*X.akk l l^8+= 8+v!0- !0H"+= "+L > :  !))-_E 48	&0(  M  M M  M K  K G  G("J."A2:	:-: : 	:
 :z,#	,#!,#/2,#$,#r    