U
    eT                     @   s:   d Z ddlZddlZddlZd
ddZdd Zdd	 ZdS )z
Utilities
~~~~~~~~~
    NFc                 C   s.   | j rdd | jD }|d S |r*|  S dS )a  
    Returns the `argparse._SubParsersAction` instance for given
    :class:`argparse.ArgumentParser` instance as would have been returned by
    :meth:`argparse.ArgumentParser.add_subparsers`. The problem with the latter
    is that it only works once and raises an exception on the second attempt,
    and the public API seems to lack a method to get *existing* subparsers.

    :param create:
        If `True`, creates the subparser if it does not exist. Default if
        `False`.

    c                 S   s   g | ]}t |tjr|qS  )
isinstanceargparse_SubParsersAction).0ar   r   i/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2023.9/lib/python3.8/site-packages/argh/utils.py
<listcomp>#   s     z"get_subparsers.<locals>.<listcomp>r   N)_subparsers_actionsadd_subparsers)parsercreateactionsr   r   r   get_subparsers   s    r   c                 C   s@   t | dr| j} q t| }t| r<|j|jdd d}|S )z
    Returns argument specification for given function.  Omits special
    arguments of instance methods (`self`) and static methods (usually `cls`
    or something like this).
    __wrapped__   N)args)hasattrr   inspectgetfullargspecismethod_replacer   )functionspecr   r   r   get_arg_spec,   s    


r   c                 C   s<   t d| }|s| S |d}t|}t d| dd| S )z
    Given a multi-line string, decreases indentation of all lines so that the
    first non-empty line has zero indentation and the remaining lines are
    adjusted accordingly.
    z	(^|
)( +)   z(^|\n) {}z\1)rematchgrouplensub)textr   Zfirst_line_indentationdepthr   r   r   unindent:   s    
r%   )F)__doc__r   r   r   r   r   r%   r   r   r   r   <module>
   s   
