o
    Thf                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZmZ er@ddlmZ dd	lmZmZmZ d
ee ddddddddde	fddZdddZded
ee ddfddZdS )zO
Command-line completion mechanisms, executed by the core ``--complete`` flag.
    )ListN)TYPE_CHECKING   )Exit
ParseError)debugtask_name_sort_key)
Collection)ParserParseResultParserContextnamescorer   initial_contextr   
collectionr	   parserr
   returnc              
   C   s  t dd| d|j}td| t|}|r|d dr|d }td| ztd| |	|}W n( t
yd }	 zd	}
t|
|	|	j |	jd urX|	jgng }W Y d }	~	nd }	~	ww td
| |rr|d su|}n|d }td| td||j ||jvrtd |drtdd | D ]}t| qt|dkr| D ]}t| qt	 t|j| jrtd 	 ttd t| ttd t| t)Nz^({}) | zCompleting for invocation: {!r}-z#Invocation's tail {!r} is flag-likez$Seeking context name in tokens: {!r}z<Got parser error ({!r}), grabbing its last-seen context {!r}z!Parsed invocation, contexts: {!r}zSelected context: {!r}zLooking for {!r} in {!r}z%Not found, completing with flag names--c                 S   s
   |  dS )Nr   )
startswith)x r   M/var/www/html/venv/lib/python3.10/site-packages/invoke/completion/complete.py<lambda>@   s   
 zcomplete.<locals>.<lambda>z-Found, and it takes a value, so no completionz*Found, takes no value, printing task namesz4Last token isn't flag-like, just printing task names)resubformatjoin	remainderr   shlexsplitr   
parse_argvr   contextflagsfilter
flag_namesprinttakes_valueprint_task_namesr   )r   r   r   r   r   
invocationtokenstailcontextsemsgr%   namer   r   r   complete   sZ   	
"




r3   c                 C   s8   t | jtdD ]}t| | j| D ]}t| qqd S )N)key)sorted
task_namesr   r)   )r   r2   aliasr   r   r   r+   a   s   
r+   shellc                 C   s   dd t  tjtjtjtdD }z||  }W n ty3   d}t|	| dt
|w td	| |d }t|d}t| j	|d	|d
 W d    d S 1 s^w   Y  d S )Nc                 S   s&   i | ]}t jt j|d  |qS )r   )ospathsplitextbasename).0r   r   r   r   
<dictcomp>m   s    z+print_completion_script.<locals>.<dictcomp>z*.completionz:Completion for shell "{}" not supported (options are: {}).z, z"Printing completion script from {}r   r )binaryspaced_names)globr9   r:   r    dirnamerealpath__file__KeyErrorr   r   r5   r   openr)   read)r8   r   completionsr:   errrA   scriptr   r   r   print_completion_scriptj   s(   "rM   )r   r	   r   N)__doc__typingr   rC   r9   r   r"   r   
exceptionsr   r   utilr   r   r   r	   r   r
   r   r   strr3   r+   rM   r   r   r   r   <module>   s6    

M	