o
    Žõ±jI.  ã                   @   s´   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZdgZdZ	dZ
dd„ Zdd„ ZG d	d
„ d
eƒZddd„ZG dd„ deƒZejdd„ ƒZdd„ ZedkrXeƒ  dS dS )é    NÚmake_completion_from_argparsez1.2ao  #compdef {{ script.name }}
# ------------------------------------------------------------------------------
# Copyright (c) {{ script.c_year }} {{ script.author }}
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of the project nor the
#     names of its contributors may be used to endorse or promote products
#     derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for {{ script.name }}.
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * {{ script.author }}
#
# ------------------------------------------------------------------------------
# Generated with zpycompletion v{{ version }}
{% for subparser_cmd in script.subparser_cmds %}

{{ subparser_cmd.name }}() {
  _arguments \
  {% for line in subparser_cmd.arguments %}
    {{ line }}
  {% endfor %}
}
{% endfor %}

{% for subparser in script.subparsers %}

{{ subparser.name }}() {
  local -a _subparser_cmds
  _subparser_cmds=(
    {% for action in subparser.actions %}
    "{{ action.name }}:{{ action.help }}"
    {% endfor %}
  )

  if (( CURRENT == {{ subparser.position }} )); then
    _describe "commands" _subparser_cmds
  else
    local curcontext="$curcontext"
    cmd="${${_subparser_cmds[(r)$words[{{ subparser.position }}]:*]%%:*}}"
    if (( $#cmd )); then
      if (( $+functions[{{ subparser.name }}_cmd_$cmd] )); then
        {% if subparser.position > 1 -%}
        (( CURRENT -= {{ subparser.position - 1 }} ))
        shift {{ subparser.position - 1 }} words
        {% endif -%}
        {{ subparser.name }}_cmd_$cmd CURRENT
      else
        _files
      fi
    else
      _message "unknown command: $words[{{ subparser.position }}]"
    fi
  fi
}
{% endfor %}
_arguments \
{% for line in script.arguments %}
  {{ line }}
{% endfor %}
c                 C   s   t | jƒrt| jƒd S dS )NéÿÿÿÿÚ )ÚlenÚoption_stringsÚsorted)Úaction© r	   ú‰/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pypykatz/argparsertest.pyÚ_actions_sort�   s   
r   c                 C   s8   d}| j rdd | j ¡ d }|S t| jtjƒrd}|S )Nr   z:(ú ú)z:_files)ÚchoicesÚjoinÚ
isinstanceÚtypeÚargparseÚFileType)r   Úzarg_actionr	   r	   r
   Ú_argument_action”   s   þr   c                   @   s   e Zd Zdd„ Zddd„ZdS )Ú_ZshCompletionc                 C   s8   || _ g | _g | _g | _t| j jtd�}|  |¡| _d S )N)Úkey)ÚparserÚ	argumentsÚ
subparsersÚsubparser_cmdsr   Ú_actionsr   Ú_parse_actions)Úselfr   Úactionsr	   r	   r
   Ú__init__�   s   z_ZshCompletion.__init__Nc              
   C   s¢  g }d }d}|D ]Ù}t |tjƒr||f}qt |tjƒr!| d¡ qt|jƒdkrst |jtƒrP|jdkrPt	|||j ƒD ]}| d 
||jt|ƒ¡¡ |d7 }q;q|jtjddfv r\d}n|jdv rkd	t|ƒ }|d7 }|d
|j 7 }nat|jƒdkr‚d	|jd  }	n
dd |j¡ d }	t |tjƒr£d|	 d 
|j|j dd¡¡ }n1t |tjƒr¸|	d 
|j|j dd¡¡ }nt |tjƒrÃ|	d }nt |tjƒrÓ|	d |j d }nq|t|ƒd	 7 }| |¡ q|�r;|\}}
tdd„ |jƒ}|jtjkrùdn|j}|pÿdd | }| j t||
|d�¡ | d 
||¡¡ |j ¡ D ]\}}d 
||¡}| j|j|d�}| j t||d�¡ �qt	t|ƒd ƒD ]}|| d ||< �qC|S )Né   z{-h,--help}"[show help text]"r   z"{0}::{1}{2}"Ú*ú+z"*)Nr!   ú?ú"ú:Ú{ú,z}"z"*"z	[{0}]:{1}Ú_r   z[show version information]ú[ú]c                 S   s   t | j| jd�S )N)ÚnameÚhelp)ÚdictÚdestr-   )Úar	   r	   r
   Ú<lambda>Ñ   s    z/_ZshCompletion._parse_actions.<locals>.<lambda>r   Ú
_subparser)r,   Úpositionr   z"*::{0}:{1}"z{0}_cmd_{1})Úsubparser_name)r,   r   z \) r   r   Ú_SubParsersActionÚ_HelpActionÚappendr   r   ÚnargsÚintÚrangeÚformatr/   r   Ú	REMAINDERÚstrr   Ú_AppendActionr-   ÚreplaceÚ_StoreActionÚ_VersionActionÚ_StoreConstActionÚmapÚ_choices_actionsÚSUPPRESSr   r.   Ú_name_parser_mapÚitemsr   r   r   )r   r   r4   ÚlinesÚ	subparserÚ
positionalr   r)   ÚlineÚoptionsr3   Úsubp_actionsÚ	subp_destÚ	subp_namer   ÚvalueÚsubp_cmd_nameÚsubp_cmd_argumentsÚir	   r	   r
   r   ¥   sd   


"
z_ZshCompletion._parse_actions©N)Ú__name__Ú
__module__Ú__qualname__r    r   r	   r	   r	   r
   r   œ   s    r   Tc                 C   s.   i }t | ƒ}|j|d< |j|d< |j|d< |S )a  
	Create a zsh completion file from a :py:class:`argparse.ArgumentParser`
	instance.

	:param parser: The parser instance to build completions for.
	:type parser: :py:class:`argparse.ArgumentParser`
	:param bool input_prompt: Whether to prompt for user input or not.
	r   r   r   )r   r   r   r   )r   ÚdestinationÚinput_promptÚscriptÚzsh_compr	   r	   r
   r   à   s   	


c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_FakeArgparsec                 C   s
   d | _ d S rT   )r   )r   r	   r	   r
   r      s   
z_FakeArgparse.__init__c                 C   s   |dkr| j S tt|ƒS )NÚArgumentParser)Ú_hookÚgetattrr   )r   r,   r	   r	   r
   Ú__getattr__  s   
z_FakeArgparse.__getattr__c                 O   s   t j|i |¤Ž| _| jS rT   )r   r]   r   )r   ÚargsÚkwargsr	   r	   r
   r^   
  s   z_FakeArgparse._hookN)rU   rV   rW   r    r`   r^   r	   r	   r	   r
   r\     s    r\   c                  c   sh   � t j} t j}ttjdƒt _ttjdƒt _zzd V  W n ty#   ‚ w W | t _|t _d S | t _|t _w )NÚw)ÚsysÚstdoutÚstderrÚopenÚosÚdevnullÚ	Exception)re   rf   r	   r	   r
   Ú_muted_std_streams  s   €
ÿÿ
ÿrk   c                  C   sÂ  t  ¡ } | jdddddd� | jddd	d
d� | jdddddd� | jddd� |  ¡ }tj |j¡}tj |¡sAt	d| ƒ d S tj 
|¡\}}tj |¡ |}| d¡r\|d d… }dt_tƒ tjd< t	d| ƒ zt ||¡}W n ty�   t	dƒ Y d S w t||jƒs–t	d |j¡ƒ t	dƒ d S |dgt_ztƒ � t||jƒƒ  W d   ƒ n1 s±w   Y  W n	 tyÀ   Y nw tjd jsÒt	d ||j¡ƒ d S ttjd j|j|jd� d S ) Nz-mz--methodÚtarget_functionÚmainz6the function which creates the ArgumentParser instance)r/   Údefaultr-   z-oz--outputÚoutputz(the path to write the completion file to)r/   r-   z--no-promptrY   TÚstore_falsezdo not prompt for input)r/   rn   r   r-   rZ   zthe python script to load from)r-   z[-] invalid script file: z.pyéýÿÿÿr   z[*] importing: z$[!] failed to import the python filez.[-] the specified script has no {0}() functionz1[-] can not automatically get the parser instancez--helpz&[-] no parser was created in {0}.{1}())rX   rY   )r   r]   Úadd_argumentÚ
parse_argsrh   ÚpathÚabspathrZ   ÚisfileÚprintÚsplitrd   r7   ÚendswithÚdont_write_bytecoder\   ÚmodulesÚimpÚload_sourceÚSyntaxErrorÚhasattrrl   r;   Úargvrk   r_   Ú
SystemExitr   r   ro   rY   )r   r   rZ   Úscript_pathÚscript_nameÚscript_import_nameÚmoduler	   r	   r
   rm     sR   
þ
ÿ€ÿrm   Ú__main__)NT)r   Ú
contextlibÚdatetimer|   rh   Úpwdrd   Újinja2Ú__all__Ú__version__ÚZSH_COMPLETION_TEMPLATEr   r   Úobjectr   r   r\   Úcontextmanagerrk   rm   rU   r	   r	   r	   r
   Ú<module>   s,   "	X
D!
,
ÿ