
    Vi              	          S SK r S SKrS SKrS SKrS SKJr  S SKJrJ	r	  S SK
Jr  S SKJrJr  S SKJrJrJrJrJrJr  S SKJrJrJrJrJrJrJrJrJ r    \!  S r$S	 r%S
 r&S r'\%\%\&\&\'S.r(Sr)S r*S r+ " S S\,5      r- " S S\,5      r. " S S\,5      r/ " S S\,5      r0 " S S\,5      r1\." S\#SSSSS9r2S r3 " S  S!\,5      r4S+S" jr5 " S# S$\,5      r6 " S% S&\,5      r7 " S' S(\,5      r8 " S) S*\,5      r9g! \" a    \#r! Nf = f),    N)OrderedDict)splitunique)OrderedMultiDict)format_exp_reprformat_nonexp_repr)ERRORget_type_descflag_to_identifiernormalize_flag_nameprocess_command_nameget_minimal_executable)	FaceExceptionArgumentParseErrorArgumentArityErrorInvalidSubcommandUnknownFlagDuplicateFlagInvalidFlagArgumentInvalidPositionalArgumentMissingRequiredFlagsc                 B    U R                  5       R                  SS5      $ )N-_)lowerreplaceargs    ^/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/face/parser.py_arg_to_subcmdr    "   s    99;sC((    c                 V    [        U5      S:  a  [        R                  " X5      eUS   $ )zIRaise a DuplicateFlag if more than one value is specified for an argument   r   )lenr   
from_parseflagarg_val_lists     r   _multi_errorr)   &   s*    
<1&&t::?r!   c                 T    U Vs/ s H  o"U R                   Ld  M  UPM     nnU$ s  snf )z3Return a list of all arguments specified for a flag)missing)r'   r(   vrets       r   _multi_extendr.   -   s)    "
<lt||&;1lC
<J =s   %%c                     US   $ )z2Return only the last argument specified for a flag r&   s     r   _multi_overrider2   3   s    r!   )errorFextendToverridezFabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!*+./?@_c                     U nU S   S:X  a  [        U 5      S:  a  U SS  n [        U 5      S:  a  [        SU-  5      eU [        ;  a  [        SU-  5      eU $ )Nr   r   r#   zPchar flags must be exactly one character, optionally prefixed by a dash, not: %rz`expected valid flag character (ASCII letters, numbers, or shell-compatible punctuation), not: %r)r$   
ValueError_VALID_CHARS)char	orig_chars     r   _validate_charr;   A   sz    IAw#~#d)a-ABx
4y1} 8:CD E 	E< FHQR S 	SKr!   c                     U nUR                   b   UR                  S:  d  UR                   S:  a  U$ UR                   S:X  a  U(       a  US   $ S$ [        SU < SU< 35      e)a  Automatically unwrap injectable posargs into a more intuitive
format, similar to an API a human might design. For instance, a
function which takes exactly one argument would not take a list of
exactly one argument.

Cases as follows:

1. min_count > 1 or max_count > 1, pass through posargs as a list
2. max_count == 1 -> single argument or None

Even if min_count == 1, you can get a None back. This compromise
was made necessary to keep "to_cmd_scope" robust enough to pass to
help/error handler funcs when validation fails.
Nr#   r   z)invalid posargspec/posargs configuration z -- )	max_count	min_countRuntimeError)
posargspecposargspass      r   _posargs_to_providesrC   N   sb    " C
}} 1S]]Q5F
}}$wqz.$.
$g/ 0 0r!   c                   .    \ rS rSrSrSS jrS rS rSrg)	CommandParseResulti   at  The result of :meth:`Parser.parse`, instances of this type
semantically store all that a command line can contain. Each
argument corresponds 1:1 with an attribute.

Args:
   name (str): Top-level program name, typically the first
      argument on the command line, i.e., ``sys.argv[0]``.
   subcmds (tuple): Sequence of subcommand names.
   flags (OrderedDict): Mapping of canonical flag names to matched values.
   posargs (tuple): Sequence of parsed positional arguments.
   post_posargs (tuple): Sequence of parsed post-positional
      arguments (args following ``--``)
   parser (Parser): The Parser instance that parsed this
      result. Defaults to None.
   argv (tuple): The sequence of strings parsed by the Parser to
      yield this result. Defaults to ``()``.

Instances of this class can be injected by accepting the "args_"
builtin in their Command handler function.

c                 v    Xl         [        U5      U l        S U l        S U l        S U l        S U l        S U l        g N)parsertupleargvnamesubcmdsflagsrA   post_posargs)selfrI   rK   s      r   __init__CommandParseResult.__init__   s6    $K		
 r!   c           	      D   U R                   (       a#  U R                  R                  U R                      OU R                  nU R                  (       d  U R                  R                  nOhU R                  S   n[
        R                  R                  U5      u  p4US:X  a2  [
        R                  R                  U5      n[        5       nU< SU< 3nU UU R                   U R                  U R                  U R                  UU R                  S.nU R                  (       a  UR                  U R                  5        U R                   (       d  U R                  O"U R                  R                  U R                      nUR                  R                  (       a8  [        UR                  U R                  5      n	XUR                  R                  '   UR                  R                  (       a8  [        UR                  U R                  5      n	XUR                  R                  '   U$ )z<returns a dict which can be used as kwargs in an inject callr   z__main__.pyz -m )args_cmd_subcmds_flags_posargs_post_posargs_subcommand_command_)rM   rI   
subprs_maprK   rL   ospathr   basenamer   rN   rA   rO   updateprovidesrC   )
rP   
_subparserrU   r^   r_   pkg_nameexecutable_pathr-   prsposargs_providess
             r   to_cmd_scopeCommandParseResult.to_cmd_scope   sp   =A\\T[[++DLL9t{{
yy;;##D99Q<DWW]]40ND=(77++D1"8":%4h?<<<< $ 1 1(;;( ::JJtzz"!%dkk4;;3I3I$,,3W;;3CKKN(8$$%$$3CKKARARS-=  ))*
r!   c                     [        U / SQ5      $ )N)rL   rK   rI   r   rP   s    r   __repr__CommandParseResult.__repr__   s    !$(BCCr!   )rK   rN   rL   rI   rA   rO   rM   N)r1   )	__name__
__module____qualname____firstlineno____doc__rQ   rg   rl   __static_attributes__r1   r!   r   rE   rE   i   s    *!!FDr!   rE   c                   :    \ rS rSrSr\SSSSS4S jrS rS rSr	g)	Flag   aw  The Flag object represents all there is to know about a resource
that can be parsed from argv and consumed by a Command
function. It also references a FlagDisplay, used by HelpHandlers
to control formatting of the flag during --help output

Args:
   name (str): A string name for the flag, starting with a letter,
      and consisting of only ASCII letters, numbers, '-', and '_'.
   parse_as: How to interpret the flag. If *parse_as* is a
     callable, it will be called with the argument to the flag,
     the return value of which is stored in the parse result. If
     *parse_as* is not a callable, then the flag takes no
     argument, and the presence of the flag will produce this
     value in the parse result. Defaults to ``str``, meaning a
     default flag will take one string argument.
   missing: How to interpret the absence of the flag. Can be any
     value, which will be in the parse result when the flag is not
     present. Can also be the special value ``face.ERROR``, which
     will make the flag required. Defaults to ``None``.
   multi (str): How to handle multiple instances of the same
     flag. Pass 'overwrite' to accept the last flag's value. Pass
     'extend' to collect all values into a list. Pass 'error' to
     get the default behavior, which raises a DuplicateFlag
     exception. *multi* can also take a callable, which accepts a
     list of flag values and returns the value to be stored in the
     :class:`CommandParseResult`.
   char (str): A single-character short form for the flag. Can be
     user-friendly for commonly-used flags. Defaults to ``None``.
   doc (str): A summary of the flag's behavior, used in automatic
     help generation.
   display: Controls how the flag is displayed in automatic help
     generation. Pass False to hide the flag, pass a string to
     customize the label, and pass a FlagDisplay instance for full
     customizability.
Nr3   c                    [        U5      U l        X`l        X l        X0l        U[
        L a  [        U5      (       d  [        SU-  5      eU(       a  [        U5      OS U l	        [        U5      (       a  X@l
        OGU[        ;   a  [        U   U l
        O.[        S[        [        R                  5       5      < SU< 35      eU R                  U5        g )Nzocannot make an argument-less flag required. expected non-ERROR for missing, or a callable for parse_as, not: %rz)multi expected callable, bool, or one of , not: )r   rL   docparse_asr+   r	   callabler7   r;   r9   multi_MULTI_SHORTCUTSlistkeysset_display)rP   rL   rz   r+   r|   r9   ry   displays           r   rQ   Flag.__init__   s    &t,	 eHX$6$6 68@A B B -1N4(d	E??J&&)%0DJ $%5%:%:%< =uF G G 	!r!   c                    Uc  0 nO8[        U[        5      (       a
  SU(       + 0nO[        U[        5      (       a  SU0n[        U[        5      (       a  [	        U 40 UD6n[        U[        5      (       d  [        SU-  5      eXl        g)zControls how the flag is displayed in automatic help
generation. Pass False to hide the flag, pass a string to
customize the label, and pass a FlagDisplay instance for full
customizability.
NhiddenlabelzSexpected bool, text name, dict of display options, or FlagDisplay instance, not: %r)
isinstanceboolstrdictFlagDisplay	TypeErrorr   )rP   r   s     r   r   Flag.set_display   s     ?G&&W-G%%(Ggt$$!$2'2G';// I%& ' ' r!   c                 $    [        U SS/SS/S S9$ )NrL   rz   r+   r|   c                     U S [         4;  $ rH   )r)   )r,   s    r   <lambda>Flag.__repr__.<locals>.<lambda>  s    AdL=Q4Qr!   opt_keyrj   rk   s    r   rl   Flag.__repr__   s$    !$(<y'>R*QS 	Sr!   )r9   r   ry   r+   r|   rL   rz   )
rn   ro   rp   rq   rr   r   rQ   r   rl   rs   r1   r!   r   ru   ru      s(    "F '*4wd",(Sr!   ru   c                   4    \ rS rSrSrS r\S 5       rS rSr	g)r   i  a0  Provides individual overrides for most of a given flag's display
settings, as used by HelpFormatter instances attached to Parser
and Command objects. Pass an instance of this to
Flag.set_display() for full control of help output.

FlagDisplay instances are meant to be used 1:1 with Flag
instances, as they maintain a reference back to their associated
Flag. They are generally automatically created by a Flag
constructor, based on the "display" argument.

Args:
   flag (Flag): The Flag instance to which this FlagDisplay applies.
   label (str): The formatted version of the string used to
     represent the flag in help and error messages. Defaults to
     None, which allows the label to be autogenerated by the
     HelpFormatter.
   post_doc (str): An addendum string added to the Flag's own
     doc. Defaults to a parenthetical describing whether the flag
     takes an argument, and whether the argument is required.
   full_doc (str): A string of the whole flag's doc, overriding
     the doc + post_doc default.
   value_name (str): For flags which take an argument, the string
     to use as the placeholder of the flag argument in help and
     error labels.
   hidden (bool): Pass True to hide this flag in general help and
     error messages. Defaults to False.
   group: An integer or string indicating how this flag should be
     grouped in help messages, improving readability. Integers are
     unnamed groups, strings are for named groups. Defaults to 0.
   sort_key: Flags are sorted in help output, pass an integer or
     string to override the sort order.

c                    Xl         UR                  U l        U R                  cG  [        UR                  5      (       a-  [	        UR                  5      u  p4SU-   U l        US:X  a  X@l        UR                  SS 5      U l        UR                  SS 5      U l        SU l        [        UR                  5      (       aB  UR                  SS 5      =(       d$    U R                   R                  R                  5       U l        UR                  SS5      U l        UR                  S	S
5      U l        UR                  SS 5      U l        UR                  SS5      U l        U(       a  [        SUR!                  5       -  5      eg )NzParsed with aspost_docfull_doc 
value_namegroupr   r   Fr   sort_key unexpected keyword arguments: %r)r'   ry   r{   rz   r
   popr   r   r   rL   upperr   _hider   r   r   r   )rP   r'   kw_prepdescs        r   rQ   FlagDisplay.__init__(  s   	8888 7 7'6KE%,DH}z40z40DMM"" ff\48RDIINN<P<P<RDOVVGQ'
VVHe,
VVGT*
z1-
 >JKKr!   c                 F    U R                   =(       d    U R                  S:H  $ Nr   r   r   rk   s    r   r   FlagDisplay.hiddenF      zz-TZZ2--r!   c                 *    [        U SS/SS/[        S9$ )Nr   ry   r   r   r   )r   r   rk   s    r   rl   FlagDisplay.__repr__J  s    !$%(87H:MW[\\r!   )	r   ry   r'   r   r   r   r   r   r   N
rn   ro   rp   rq   rr   rQ   propertyr   rl   rs   r1   r!   r   r   r     s'     D< . .]r!   r   c                   4    \ rS rSrSrS r\S 5       rS rSr	g)PosArgDisplayiN  a  Provides individual overrides for PosArgSpec display in automated
help formatting. Pass to a PosArgSpec constructor, which is in
turn passed to a Command/Parser.

Args:
   spec (PosArgSpec): The associated PosArgSpec.
   name (str): The string name of an individual positional
     argument. Automatically pluralized in the label according to
     PosArgSpec values. Defaults to 'arg'.
   label (str): The full display label for positional arguments,
     bypassing the automatic formatting of the *name* parameter.
   doc (str): A summary description of the positional arguments.
   post_doc (str): An informational addendum about the arguments,
     often describes default behavior.

c                 B   UR                  SS 5      =(       d    SU l        UR                  SS5      U l        UR                  SS 5      U l        UR                  SS5      U l        UR                  SS 5      U l        U(       a  [        S	UR                  5       -  5      eg )
NrL   r   ry   r   r   r   Fr   r   )r   rL   ry   r   r   r   r   r   )rP   r   s     r   rQ   PosArgDisplay.__init___  s~    FF64(1E	66%$z40VVHe,
VVGT*
>JKKr!   c                 F    U R                   =(       d    U R                  S:H  $ r   r   rk   s    r   r   PosArgDisplay.hiddenj  r   r!   c                     [        U SS/5      $ )NrL   r   rj   rk   s    r   rl   PosArgDisplay.__repr__n  s    !$(9::r!   )r   ry   r   rL   r   Nr   r1   r!   r   r   r   N  s%     	 . .;r!   r   c                   H    \ rS rSrSr\SSSS4S jrS r\S 5       r	S r
Srg)	
PosArgSpecir  a`  Passed to Command/Parser as posargs and post_posargs parameters to
configure the number and type of positional arguments.

Args:
   parse_as (callable): A function to call on each of the passed
      arguments. Also accepts special argument ERROR, which will raise
      an exception if positional arguments are passed. Defaults to str.
   min_count (int): A minimimum number of positional
      arguments. Defaults to 0.
   max_count (int): A maximum number of positional arguments. Also
      accepts None, meaning no maximum. Defaults to None.
   display: Pass a string to customize the name in help output, or
      False to hide it completely. Also accepts a PosArgDisplay
      instance, or a dict of the respective arguments.
   provides (str): name of an argument to be passed to a receptive
      handler function.
   name (str): A shortcut to set *display* name and *provides*
   count (int): A shortcut to set min_count and max_count to a single value
      when an exact number of arguments should be specified.

PosArgSpec instances are stateless and safe to be used multiple
times around the application.

Nc                     [        U5      (       d  U[        La  [        SU-  5      eUR                  SS 5      nUR                  SS 5      nU(       a%  [        S[	        UR                  5       5      -  5      eXl        Uc  UOUnUc  UOUnU(       a  [        U5      OSU l        Ub  [        U5      OS U l	        U R                  S:  a  [        SU R                  -  5      eU R                  b(  U R                  S::  a  [        SU R                  -  5      eU R                  (       aA  U R                  U R                  :  a'  [        SU R                  < S	U R                  < 35      eUc  UOUnXPl        Uc  0 nO8[        U[        5      (       a
  S
U(       + 0nO[        U[        5      (       a  SU0n[        U[        5      (       a  UR!                  SU5        [#        S0 UD6n[        U["        5      (       d  [        SU-  5      eX@l        g )Nz/expected callable or ERROR for parse_as, not %rrL   countr   r   z expected min_count >= 0, not: %rzexpected max_count > 0, not: %rz%expected min_count > max_count, not: z > r   zUexpected bool, text name, dict of display options, or PosArgDisplay instance, not: %rr1   )r{   r	   r   r   r~   r   rz   intr>   r=   r7   ra   r   r   r   r   
setdefaultr   r   )	rP   rz   r>   r=   r   ra   kwargsrL   r   s	            r   rQ   PosArgSpec.__init__  s   !!he&;MPXXYYzz&$'

7D)>fkkmATTUU  '.EI	&.EI	+4Y!+4+@Yd>>A?$..PQQ>>%$..A*=>OPP>>dnnt~~= $@ A A $+4 ?G&&W-G%%w'Ggt$$vt,#.g.G'=11 K%& ' ' r!   c                     [        U / SQ5      $ )N)rz   r>   r=   r   rj   rk   s    r   rl   PosArgSpec.__repr__  s    !$(YZZr!   c                 &    U R                   [        L$ )zGTrue if this PosArgSpec is configured to accept one or
more arguments.
)rz   r	   rk   s    r   accepts_argsPosArgSpec.accepts_args  s    
 }}E))r!   c                 R   [        U5      nU(       a  U R                  (       d  [        SU-  5      eU R                  U R                  pCX4:X  a  SU-  nUS:  a  US-  nO>US:X  a  SU-  nXT(       a  US:  a  SOS-  nOUc  S	U-  nXSS:  a  SOS-  nO
U< S
U< S3nX#:  a  [        SU< SU< 35      eUb  X$:  a  [        SU< SU< 35      e/ nU H&  n U R                  U5      nUR                  U5        M(     U$ ! [         a  n	[        R                  " XU	5      eSn	A	ff = f)a  Parse a list of strings as positional arguments.

Args:
   posargs (list): List of strings, likely parsed by a Parser
      instance from sys.argv.

Raises an ArgumentArityError if there are too many or too few
arguments.

Raises InvalidPositionalArgument if the argument doesn't match
the configured *parse_as*. See PosArgSpec for more info.

Returns a list of arguments, parsed with *parse_as*.
z#unexpected positional arguments: %rz%s argumentr#   sr   zup to %s argumentr   Nzat least %s argumentz - z
 argumentsztoo few arguments, expected z, got ztoo many arguments, expected )
r$   r   r   r>   r=   rz   append	Exceptionr   r%   )
rP   rA   len_posargsr>   r=   arg_range_textr-   pavalexcs
             r   parsePosArgSpec.parse  sK    'l4,,$%JW%TUU#~~t~~9!*Y6N1}#%A~!4y!@)	A#BN"!7)!CQ#B>8A9!M"$(6&E F F [%<$(6&E F FB mmB' 

3  
	  J/::4SIIJs   D  
D&
D!!D&)r   r=   r>   rz   ra   )rn   ro   rp   rq   rr   r   rQ   rl   r   r   r   rs   r1   r!   r   r   r   r  s:    0 !$ttT\` )Z[ * *1r!   r   z
--flagfiler4   Fr   )rz   r|   r+   r   ry   c                    U (       d  [        [        S9n OU SL a  [        5       n Ox[        U [        5      (       a
  [        X S9n OY[        U [        5      (       a
  [        X S9n O:[        U [
        5      (       a  [        S0 U D6n O[        U 5      (       a	  [        U S9n [        U [         5      (       d  [        SU< SU < 35      eU $ )N)rz   T)r>   r=   )r   ra   z	expected zp as True, False, number of args, text name of args, dict of PosArgSpec options, or instance of PosArgSpec, not: r1   )r   r	   r   r   r   r   r{   r   )rA   posargs_names     r   _ensure_posargspecr     s    e,	D,	GS	!	! wB	GS	!	!W?	GT	"	"'w'	'		g.gz**'2 3 	3 Nr!   c                   ~    \ rS rSrSr  SS jrSS jrSS jrS rS r	S	 r
S
 rS rS rS rS rSS jrSS jrSrg)Parseri  aC  The Parser lies at the center of face, primarily providing a
configurable validation logic on top of the conventional grammar
for CLI argument parsing.

Args:
   name (str): A name used to identify this command. Important
      when the command is embedded as a subcommand of another
      command.
   doc (str): An optional summary description of the command, used
      to generate help and usage information.
   flags (list): A list of Flag instances. Optional, as flags can
      be added with :meth:`~Parser.add()`.
   posargs (bool): Defaults to disabled, pass ``True`` to enable
      the Parser to accept positional arguments. Pass a callable
      to parse the positional arguments using that
      function/type. Pass a :class:`PosArgSpec` for full
      customizability.
   post_posargs (bool): Same as *posargs*, but refers to the list
      of arguments following the ``--`` conventional marker. See
      ``git`` and ``tox`` for examples of commands using this
      style of positional argument.
   flagfile (bool): Defaults to enabled, pass ``False`` to disable
      flagfile support. Pass a :class:`Flag` instance to use a
      custom flag instead of ``--flagfile``. Read more about
      Flagfiles below.

Once initialized, parsing is performed by calling
:meth:`Parser.parse()` with ``sys.argv`` or any other list of strings.
Nc                 &   [        U5      U l        X l        [        U=(       d    / 5      n[	        US5      U l        [	        US5      U l        USL a  [        U l        O9[        U[        5      (       a  X`l        OU(       d  S U l        O[        SU-  5      e[        5       U l        [        5       U l        [        5       U R                  S'   U H  nU R                  U5        M     U R                  (       a  U R                  U R                  5        g )NrA   rO   Tz<expected True, False, or Flag instance for flagfile, not: %rr1   )r   rL   ry   r~   r   rA   rO   FLAGFILE_ENABLEDflagfile_flagr   ru   r   r   r\   _path_flag_mapadd)rP   rL   ry   rN   rA   rO   flagfiler'   s           r   rQ   Parser.__init__2  s    (.	U[b!)'9=.|^Lt!1D$''!)!%D 13;< = = &-)m"--BDHHTN HHT''(r!   c                     U R                   U   n[        UR                  5        VVs/ s H,  u  pEU(       d  UR                  R                  (       a  M)  XE4PM.     snn5      $ s  snnf rH   )r   r   itemsr   r   )rP   r^   with_hiddenflag_mapkfs         r   get_flag_mapParser.get_flag_mapO  s_    &&t,x~~/? D/?tq*!))2B2B #QF/? D E 	E Ds   (A#
A#
c                 R    U R                  XS9n[        UR                  5       5      $ )N)r^   r   )r   r   values)rP   r^   r   r   s       r   	get_flagsParser.get_flagsT  s'    $$$$Hhoo'((r!   c                     U R                   R                  nSU< SU R                  < S[        U R                  5      < S[        U R                  5       5      < SU R                  < S3$ )N<z name=z subcmd_count=z flag_count=z	 posargs=>)	__class__rn   rL   r$   r\   r   rA   )rP   cns     r   rl   Parser.__repr__Y  sE    ^^$$tyy#doo"6DNN<L8Mt||] 	^r!   c                    U R                   R                  (       a  [        S5      e[        UR                  5      nU R
                   H  nUS   U:X  d  M  [        SU-  5      e   U R                  S   nS nUR                  R                  5        H!  u  pgU" XFU5      (       a  M  [        SU-  5      e   XR
                  U4'   [        UR
                  R                  5       5       H  u  phU4U-   n	XR
                  U	'   M     UR                  R                  5        H8  u  pgUR                  5       n
U
R                  U5        XR                  U4U-   '   M:     g)zProcess subcommand name, check for subcommand conflicts, check for
subcommand flag conflicts, then finally add subcommand.

To add a command under a different name, simply make a copy of
that parser or command with a different name.
z?commands accepting positional arguments cannot take subcommandsr   zconflicting subcommand name: %rr1   c                     g)NTr1   )parent_flag_mapsubcmd_pathsubcmd_flagss      r   r   'Parser._add_subparser.<locals>.<lambda>r  s    PTr!   z1subcommand flags conflict with parent command: %rN)rA   r   r7   r   rL   r\   r   r   r~   copyr`   )rP   subprssubprs_nameprs_pathr   check_no_conflictsr^   rN   
cur_subprsnew_path	new_flagss              r   _add_subparserParser._add_subparser^  sJ    <<$$ 8 9 9 +6;;7 H{k) !B[!PQQ ( --b1T!00668KD%oUCC !TW\!\]] 9 +1' $V%6%6%<%<%> ?D#~,H(2OOH% !@
 "00668KD',,.IU#9B 56 9r!   c           
      *   [        US   [        5      (       a  US   nU R                  U5        g[        US   [        5      (       a  US   nO [        U0 UD6nU R                  U5      $ ! [         a  n[        SU< SU< SU< S35      eSnAff = f)ag  Add a flag or subparser.

Unless the first argument is a Parser or Flag object, the
arguments are the same as the Flag constructor, and will be
used to create a new Flag instance to be added.

May raise ValueError if arguments are not recognized as
Parser, Flag, or Flag parameters. ValueError may also be
raised on duplicate definitions and other conflicts.
r   Nz0expected Parser, Flag, or Flag parameters, not: , z (got ))r   r   r   ru   r   r7   	_add_flag)rP   ar   r   r'   tes         r   r   
Parser.add  s     adF##qTF'adD!!Q4DHQ~"~ ~~d##  H <=r2"G H HHs   A+ +
B5BBc                    U R                   R                  5        H  u  p#UR                  UR                  5      =(       d.    UR                  =(       a    UR                  UR                  5      nUc  MZ  UR                  UR                  UR                  4;   a  [        SU< SUR                  < 35      eUR                  (       d  M  UR                  UR                  UR                  4;   d  M  [        SU< SU< 35      e   U R                   R                  5        H2  nXUR                  '   UR                  (       d  M$  XUR                  '   M4     g )Nzpre-existing flag z! conflicts with name of new flag z( conflicts with short form for new flag )r   r   getrL   r9   r7   r   )rP   r'   rM   r   conflict_flags        r   r   Parser._add_flag  s   !%!4!4!:!:!<G$LL3^		8]hllSWS\S\F]M$yy]//1C1CDD $1499"> ? ?yyyTYY=+=+=}?Q?Q*RR $14"9 : : "= ++224H"&TYYyyy&*# 5 	r!   c           	         Uc  [         R                  n[        XS9nU(       d  [        SU< 35      nX#l        UeU HE  n[        U[        [        45      (       a  M   [        SU< S[        U5      R                  < S35      e    SnUS   [        U5      SS pvXbl         U R                  U5      u  p[        U5      Ul        U(       a  U R                   [        U5         OU n	U R#                  [        U5      S	9n
U R%                  X5      u  p[n['        U5      Ul        [        U5      Ul        U R-                  XU5      n['        U5      Ul        SnSnS
U;   aH  [/        US
S5      u  pXsUl        Ul        U	R0                  R3                  U5      n[        U5      Ul        U	R*                  R3                  U5      n[        U5      Ul        U$ ! [         a  nX#l        e SnAff = f)aC  This method takes a list of strings and converts them into a
validated :class:`CommandParseResult` according to the flags,
subparsers, and other options configured.

Args:
   argv (list): A required list of strings. Pass ``None`` to
      use ``sys.argv``.

This method may raise ArgumentParseError (or one of its
subtypes) if the list of strings fails to parse.

.. note:: The *argv* parameter does not automatically default
          to using ``sys.argv`` because it's best practice for
          implementing codebases to perform that sort of
          defaulting in their ``main()``, which should accept
          an ``argv=None`` parameter. This simple step ensures
          that the Python CLI application has some sort of
          programmatic interface that doesn't require
          subprocessing. See here for an example.

N)rI   rK   z/expected non-empty sequence of arguments, not: z)parse expected all args as strings, not: z (r   r   r#   )r^   --)sysrK   rE   r   prs_resr   r   unicoder   typern   r~   rL   _parse_subcmdsrJ   rM   r\   r   _parse_flagsr   rN   rA   _resolve_flagsr   rO   r   )rP   rK   cpraper   r   cmd_nameargsrM   re   cmd_flag_mapflagfile_maprA   resolved_flag_maprO   parsed_post_posargsparsed_posargss                    r   r   Parser.parse  s   , <88D 8$\`%bcCKICcC>22VY[_`c[d[m[m noo 	 a$t*QR.$
$	 //5MG.CK5<$//%.1$C  ,,%.,AL /3.?.?.S+HG#H-CI.CK !% 3 3LL Y#$56CI  L"&w(-gtQ(?%07-S-&)&6&6&<&<\&J##()<#=  [[..w7N/CK
 
	 " 	K	s   "D/G 
G)G$$G)c                    / nU H  nUR                  S5      (       a    O[        U5      n[        X#/-   5      U R                  ;  ag  U(       a  U R                  [        U5         OU nUR                  R
                  [        Ld  UR                  (       d    O+[        R                  " XC5      eUR                  U5        M     X![        U5      S 4$ )zExpects arguments after the initial command (i.e., argv[1:])

Returns a tuple of (list_of_subcmds, remaining_args).

Raises on unknown subcommands.r   N)
startswithr    rJ   r\   rA   rz   r	   r   r%   r   r$   )rP   r  r-   r   re   s        r   r  Parser._parse_subcmds  s     C~~c"" %CS5[!858dooeCj1d;;''u4CNN'223<<JJsO  SO##r!   c                 
   SnUS   nS n UR                  SSS9u  pEUR                  [        U5      5      nUc  [        R
                  " X5      eUR                  n[        U5      (       d%  U(       a  [        R
                  " XU5      eXgUSS  4$  Uc  US   nSn U" U5      nXhX#S  4$ ! [         a     Nf = f! [         a    [        R
                  " XS S9ef = f! [         a  n	[        R
                  " XXYS9eS n	A	ff = f)Nr#   r   =)maxsplit   r   )r   )r   r7   r  r   r   r%   rz   r{   r   
IndexErrorr   )
rP   r  r  advancer   arg_textr'   rz   arg_vales
             r   _parse_single_flagParser._parse_single_flag%  s1   1g	IIcAI6MC  3C 89<((;;==!!)44\RR48++	O7	Vx(G d8n,,/  		   	O%00NN	O  	V%00XUU	Vs5   B+ 
B; C +
B87B8; C
D(C==Dc                    [        5       n[        5       n[        5       nUnU(       a  US   nU(       a  US   S:w  d  US:X  d  US:X  a  OU R                  X5      u  pnUR	                  UR
                  U	5        XR                  L aR  U R                  XUS9  UR                  5        H.  u  pX;   a  M  UR                  U5        UR	                  U
5        M0     U(       a  M  X4U4$ )zExpects arguments after the initial command and subcommands (i.e.,
the second item returned from _parse_subcmds)

Returns a tuple of (multidict of flag names to parsed and validated values, remaining_args).

Raises on unknown subcommands.
r   r   r  res_map)
OMDr   setr&  r   rL   r   _parse_flagfiler   update_extend)rP   r  r  flag_value_mapff_path_res_mapff_path_seen	orig_argsr   r'   valuer^   ff_flag_value_maps               r   r  Parser._parse_flagsD  s     %-u	q'C#a&C-3#: $ 7 7 KDtyy%0)))$$\/$R/>/D/D/F+D+ "001BC $$T*	 0G d  44r!   c                    Ub  UO	[        5       n[        [        USS 5      5      (       aO  [        USS 5      nU(       a  [        R                  R                  U5      O
[        U5      nUR                  5       nOQ[        R                  R                  U5      n [        R                  " USS5       nUR                  5       nS S S 5        Xc;   a  U$ [        5       =XF'   n
WR                  5       n[        US5       H  u  p [         R"                  " USS	9nU(       d  M$  U R%                  X5      u  nnnU(       a  [        S
UR&                  -  5      eU
R)                  UR&                  U5        XR*                  L a  U R-                  UUUS9  M  M     U$ ! , (       d  f       N= f! [        [        4 a  n	[        SU< SU	< 35      eS n	A	ff = f! [.         a'  nUR0                  S   SU< SU< S3-   4Ul        e S nAff = f)NreadrL   rzutf-8zfailed to load flagfile "z", got: r#   T)commentszFexcessive flags or arguments for flag "%s", expected one flag per liner)  r   z
 (on line z of flagfile "z"))r   r{   getattrr]   r^   abspathreprr7  codecsopenUnicodeErrorEnvironmentErrorr   r+  
splitlines	enumerateshlexr   r&  rL   r   r   r-  r   r  )rP   r  path_or_filer*  r-   f_namer^   ff_textr   eecur_file_reslineslinenoliner  r'   r3  leftover_argsfes                      r   r-  Parser._parse_flagfilec  s    ,g+-GL&$788\648F.4277??6*$|:LD"'')G77??<0D_[[sG<ffhG = ?N#&5(	L""$%eQ/LF{{4$7-1-D-D\-X*e] , .KMQYY.W X X   E2---((uc(J . 0& 
9 =< "23 _(TXZ\)]^^_, ! 771:FTX(YY[sU   F( 2FF( G A/G
F%!F( %F( (G8GG
H"G??Hc           
         [        5       nXpeU=(       d    0 n/ nUR                  5        H_  u  pU	R                  U;   a  M  U	R                  [        L a  UR                  U	R                  5        MG  U	R                  XiR                  '   Ma     U(       a  [        R                  " XVU5      eU H,  nXX   n	UR                  U5      n
 U	R                  X5      XH'   M.     U$ ! [         a  n/ nUR                  5        H  u  pX;   d  M  UR                  U5        M     U(       aI  [        U5      S:  a  SOSnSU< SU< SSR                  U5      < S3nUR                  S	   U-   4Ul        e S nAff = f)
Nr#   	flagfilesr   z	
	(check z with definitions for flag "z": r   r   r   )r   r   rL   r+   r	   r   r   r%   getlistr|   r   r$   joinr  )rP   r  parsed_flag_mapr  r-   cfmpfmmissing_flags	flag_namer'   r(   rM  ff_pathsff_pathff_value_mapff_labelmsgs                    r   r  Parser._resolve_flags  sK   mS#)r "yy{OIyyC||u$$$TYY/!%II  + &11#MJJ I>D;;y1L!%D!?	   
 ! 
-9-?-?-A)G 0 0 .B .1(ma.?{ZH&	499X3FHC!wwqzC/1BG
s   C
E2)E-A&E--E2)r   ry   r   rL   rA   rO   r\   )NNNNT)T)r1   TrH   )rn   ro   rp   rq   rr   rQ   r   r   rl   r   r   r   r   r  r&  r  r-  r  rs   r1   r!   r   r   r     sX    : <@-1:E
)
^
$CX$4(Un$,->5>&P"r!   r   c                 d   ^^ SSK JnJnJm   " UU4S jSU5      n[	        U" U /US95      nUS   $ )zTParse a single line of values, separated by the delimiter
*sep*. Supports quoting.

r   )readerDialectQUOTE_MINIMALc                   6   > \ rS rSr YrSrSrSrSrSr	 Y r
Srg)	$parse_sv_line.<locals>._face_dialecti  \"TF
r1   N)rn   ro   rp   rq   	delimiter
escapechar	quotechardoublequoteskipinitialspacelineterminatorquotingrs   )ra  seps   r   _face_dialectrc    s'    	
	 r!   ro  )dialect)csvr_  r`  ra  r~   )rK  rn  r_  r`  ro  parsedra  s    `    @r   parse_sv_liners    s;     32      &$78F!9r!   c                   8    \ rS rSrSr\SS4S jrS r\rS r	Sr
g	)
	ListParami  a;  The ListParam takes an argument as a character-separated list, and
produces a Python list of parsed values. Basically, the argument
equivalent of CSV (Comma-Separated Values)::

  --flag a1,b2,c3

By default, this yields a ``['a1', 'b2', 'c3']`` as the value for
``flag``. The format is also similar to CSV in that it supports
quoting when values themselves contain the separator::

  --flag 'a1,"b,2",c3'

Args:
   parse_one_as (callable): Turns a single value's text into its
      parsed value.
   sep (str): A single-character string representing the list
     value separator. Defaults to ``,``.
   strip (bool): Whether or not each value in the list should have
      whitespace stripped before being passed to
      *parse_one_as*. Defaults to False.

.. note:: Aside from using ListParam, an alternative method for
          accepting multiple arguments is to use the
          ``multi=True`` on the :class:`Flag` constructor. The
          approach tends to be more verbose and can be confusing
          because arguments can get spread across the command
          line.

,Fc                 (    Xl         X l        X0l        g rH   parse_one_asrn  strip)rP   ry  rn  rz  s       r   rQ   ListParam.__init__  s    (
r!   c                     [        XR                  5      nU R                  (       a  U Vs/ s H  o3R                  5       PM     nnU Vs/ s H  o0R                  U5      PM     sn$ s  snf s  snf )z8Parse a single string argument into a list of arguments.)rs  rn  rz  ry  )rP   	list_text
split_valsr,   s       r   r   ListParam.parse  sU    "9hh7
::-78Z'')ZJ8.89j!!!$j99 99s   A'
A,c                 "    [        U S/SS/5      $ )Nry  rn  rz  r   rk   s    r   rl   ListParam.__repr__  s    tn%5w7GHHr!   rx  N)rn   ro   rp   rq   rr   r   rQ   r   __call__rl   rs   r1   r!   r   ru  ru    s'    : %(S : HIr!   ru  c                   2    \ rS rSrSrSS jrS r\rS rSr	g)	ChoicesParami  zParses a single value, limited to a set of *choices*. The actual
converter used to parse is inferred from *choices* by default, but
an explicit one can be set *parse_as*.
Nc                     U(       d  [        SU-  5      e [        U5      U l        Uc  [        U R                  S   5      nX l        g ! [         a    [	        U5      U l         N>f = f)Nz%expected at least one choice, not: %rr   )r7   sortedchoicesr   r~   r  rz   )rP   r  rz   s      r   rQ   ChoicesParam.__init__  sa    DwNOO	)!'?DL DLLO,H   	)=DL	)s   A	 	A&%A&c                     U R                  U5      nX R                  ;  a  [        SU R                  < SU< 35      eU$ )Nzexpected one of rx   )rz   r  r   )rP   textchoices      r   r   ChoicesParam.parse	  s4    t$%$dllTX%YZZr!   c                      [        U S/S/5      $ )Nr  rz   r  rk   s    r   rl   ChoicesParam.__repr__  s    ti[:,??r!   )r  rz   rH   )
rn   ro   rp   rq   rr   rQ   r   r  rl   rs   r1   r!   r   r  r    s    ! H@r!   r  c                       \ rS rSrSrSrg)FilePathParami  zTODO

ideas: exists, minimum permissions, can create, abspath, type=d/f
(technically could also support socket, named pipe, and symlink)

could do missing=TEMP, but that might be getting too fancy tbh.
r1   Nrn   ro   rp   rq   rr   rs   r1   r!   r   r  r    s    r!   r  c                       \ rS rSrSrSrg)FileValueParami  z
TODO: file with a single value in it, like a pidfile
or a password file mounted in. Read in and treated like it
was on the argv.
r1   Nr  r1   r!   r   r  r    s    r!   r  )rv  ):r	  rC  r=  os.pathr]   collectionsr   boltons.iterutilsr   r   boltons.dictutilsr   r+  boltons.funcutilsr   r   
face.utilsr	   r
   r   r   r   r   face.errorsr   r   r   r   r   r   r   r   r   r  	NameErrorr   r    r)   r.   r2   r}   r8   r;   rC   objectrE   ru   r   r   r   r   r   r   rs  ru  r  r  r  r1   r!   r   <module>r     sJ   
    # + 5 A0 0/ / /
) *'+' /	1  X
06DD DDRPS6 PSfF]& F]R!;F !;HA AH s(DZ_egh 6YV Yx,.I .Ib@6 @<F V A   Gs   C4 4C?>C?