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rd	|jd  }	n
dd|j d }	t |tjrd|	 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rdn|j}|pd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st	d|j t	d d S |dgt_zt  t||j  W d    n1 sw   Y  W n	 ty   Y nw tjd jst	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.pyr   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!
,
