o
    i0                     @   s  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 zd d	lmZ W n eyE   d dlZY nw d
ZdZdZdZeeedZedZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Z d$d% Z!d&d' Z"dS )(    N   )Argument)MultiCommand)Option)split_arg_string)Choice)echo)abc=a  
%(complete_func)s() {
    local IFS=$'
'
    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   %(autocomplete_var)s=complete $1 ) )
    return 0
}

%(complete_func)setup() {
    local COMPLETION_OPTIONS=""
    local BASH_VERSION_ARR=(${BASH_VERSION//./ })
    # Only BASH version 4.4 and later have the nosort option.
    if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
        COMPLETION_OPTIONS="-o nosort"
    fi

    complete $COMPLETION_OPTIONS -F %(complete_func)s %(script_names)s
}

%(complete_func)setup
a  
#compdef %(script_names)s

%(complete_func)s() {
    local -a completions
    local -a completions_with_descriptions
    local -a response
    (( ! $+commands[%(script_names)s] )) && return 1

    response=("${(@f)$( env COMP_WORDS="${words[*]}" \
                        COMP_CWORD=$((CURRENT-1)) \
                        %(autocomplete_var)s="complete_zsh" \
                        %(script_names)s )}")

    for key descr in ${(kv)response}; do
      if [[ "$descr" == "_" ]]; then
          completions+=("$key")
      else
          completions_with_descriptions+=("$key":"$descr")
      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
    compstate[insert]="automenu"
}

compdef %(complete_func)s %(script_names)s
zcomplete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)")bashzshfishz[^a-zA-Z0-9_]c                 C   s>   t d| dd}t|t}|d|| |d  d S )N -_z_{}_completion)complete_funcscript_namesautocomplete_var;)_invalid_ident_char_resubreplace_completion_scriptsgetCOMPLETION_SCRIPT_BASHformatstrip)	prog_namecomplete_varshellcf_namescript r"   N/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/click/_bashcomplete.pyget_completion_script_   s   r$   c                 C   s   | j ||dd}|j|j }|rjt|jtre|jjs:|j||\}}}|du r*|S |j |||dd}|j|j }n.|r\|j||\}}}|du rL|S |j |||dddd}|j}|s<|}|j|j }n	 |S |s|S )a  Parse into a hierarchy of contexts. Contexts are connected
    through the parent variable.

    :param cli: command definition
    :param prog_name: the program that is running
    :param args: full list of args
    :return: the final context/command parsed
    T)resilient_parsingN)parentr%   F)r&   allow_extra_argsallow_interspersed_argsr%   )make_contextprotected_argsargs
isinstancecommandr   chainresolve_command)clir   r+   ctxcmd_namecmdsub_ctxr"   r"   r#   resolve_ctxl   s@   	r5   c                 C   s   | o	| dd dkS )z
    :param param_str: param_str to check
    :return: whether or not this is the start of an option declaration
        (i.e. starts "-" or "--")
    Nr   r   r"   )	param_strr"   r"   r#   start_of_option   s   r7   c                 C   sp   t |tsdS |jrdS d}ttdd | D D ]\}}|d |jkr& nt|r,|}q|r6||jv r6dS dS )aU  
    :param all_args: the full original list of args supplied
    :param cmd_param: the current command paramter
    :return: whether or not the last option declaration (i.e. starts
        "-" or "--") is incomplete and corresponds to this cmd_param. In
        other words whether this cmd_param option can still accept
        values
    FNc                 S   s   g | ]}|t kr|qS r"   )	WORDBREAK).0argr"   r"   r#   
<listcomp>   s    z(is_incomplete_option.<locals>.<listcomp>r   T)r,   r   is_flag	enumeratereversednargsr7   opts)all_args	cmd_paramlast_optionindexarg_strr"   r"   r#   is_incomplete_option   s   
	rF   c                 C   s^   t |tsdS | |j }|du rdS |jdkrdS t |tjr-|jdkr-t||jk r-dS dS )a`  
    :param current_params: the current params and values for this
        argument as already entered
    :param cmd_param: the current command parameter
    :return: whether or not the last argument is incomplete and
        corresponds to this cmd_param. In other words whether or not the
        this cmd_param argument can still accept values
    FNTr   )r,   r   namer?   r	   Iterablelen)current_paramsrB   current_param_valuesr"   r"   r#   is_incomplete_argument   s   
	



rM   c                    sV   g }t |jtr fdd|jjD }|S |jdur)|j| | d}dd |D }|S )a  
    :param ctx: context associated with the parsed command
    :param args: full list of args
    :param incomplete: the incomplete text to autocomplete
    :param cmd_param: command definition
    :return: all the possible user-specified completions for the param
    c                    s"   g | ]}t | r|d fqS N)str
startswithr9   c
incompleter"   r#   r;      s
    z,get_user_autocompletions.<locals>.<listcomp>N)r1   r+   rT   c                 S   s"   g | ]}t |tr|n|d fqS rN   )r,   tuplerQ   r"   r"   r#   r;      s    )r,   typer   choicesautocompletion)r1   r+   rT   rB   resultsdynamic_completionsr"   rS   r#   get_user_autocompletions   s   


r[   c                 c   s<    | j | D ]}||r| j | |}|js|V  qdS )z
    :param ctx: context associated with the parsed command
    :starts_with: string that visible commands must start with.
    :return: all visible (not hidden) commands that start with starts_with.
    N)r-   list_commandsrP   get_commandhidden)r1   starts_withrR   r-   r"   r"   r#   "get_visible_commands_starting_with   s   
r`   c                    s   t  jtr|dd t |D   jd urB j t  jtr; jjr; fddt |D }|dd |D   jd usd S d S )Nc                 S      g | ]	}|j | fqS r"   rH   get_short_help_strrQ   r"   r"   r#   r;      s    z.add_subcommand_completions.<locals>.<listcomp>c                    s   g | ]
}|j  jvr|qS r"   )rH   r*   rQ   r1   r"   r#   r;     s
    c                 S   ra   r"   rb   rQ   r"   r"   r#   r;     s    )r,   r-   r   extendr`   r&   r.   )r1   rT   completions_outremaining_commandsr"   rd   r#   add_subcommand_completions   s    
	
rh   c           	         s:  t | t| ||}|du rg S d v }tr.tv r.t} |d  |d ntkr4dg }|shtrh|jjD ]%t	t
rejse fddjj D }|fdd|D  q@|S |jjD ]t r|t|   S ql|jjD ]t|jrt|   S qt|| t|S )	z
    :param cli: command definition
    :param prog_name: the program that is running
    :param args: full list of args
    :param incomplete: the incomplete text to autocomplete
    :return: all the possible completions for the incomplete
    Nz--r      r   c                    s   g | ]}| vsj r|qS r"   )multiple)r9   	param_opt)rA   paramr"   r#   r;   .  s
    zget_choices.<locals>.<listcomp>c                    s    g | ]}|  r|jfqS r"   )rP   help)r9   o)rT   rl   r"   r#   r;   4  s     )copydeepcopyr5   r7   r8   	partitionappendr-   paramsr,   r   r^   r@   secondary_optsre   rF   r[   rM   rh   sorted)	r0   r   r+   rT   r1   has_double_dashpartition_incompletecompletions
param_optsr"   )rA   rT   rl   r#   get_choices  sB   




rz   c                 C   s   t tjd }ttjd }|d| }z|| }W n ty%   d}Y nw t| |||D ]}t|d  |rCt|d r@|d nd q-dS )N
COMP_WORDS
COMP_CWORDr   r   r   r   T)r   osenvironint
IndexErrorrz   r   )r0   r   include_descriptionscwordscwordr+   rT   itemr"   r"   r#   do_completeE  s   r   c                 C   sl   t tjd }tjd }|dd  }t| |||D ]}|d r-tdj|d |d d qt|d  qdS )Nr{   r|   r   z{arg}	{desc}r   )r:   descT)r   r}   r~   rz   r   r   )r0   r   r   rT   r+   r   r"   r"   r#   do_complete_fishY  s   
r   c                 C   st   d|v r| dd\}}n|}d}|dkrtt||| dS |dkr8|dkr,t| |S |dv r8t| ||d	kS d
S )Nr   r   r   sourceTcompleter   >   r   r   r   F)splitr   r$   r   r   )r0   r   r   complete_instrr-   r   r"   r"   r#   bashcompleteg  s   
r   )#ro   r}   recorer   r   r   parserr   typesr   utilsr   collectionsr	   ImportErrorr8   r   COMPLETION_SCRIPT_ZSHCOMPLETION_SCRIPT_FISHr   compiler   r$   r5   r7   rF   rM   r[   r`   rh   rz   r   r   r   r"   r"   r"   r#   <module>   sH    $
+	5