
    Vi.<                         S SK Jr  S SKrS SKJr  S SKJrJrJr  S SK	J
r
JrJr  S SKJrJr  S SKJr  S SKJrJrJrJrJrJrJr  S S	KJr  S S
KJr  S rS rS r \" 5       r! " S S\5      r"g)    )print_functionN)OrderedDict)unwrap_textget_rdep_mapecho)ArgumentParseErrorCommandLineError
UsageError)ParserFlag)HelpHandler)injectget_arg_namesis_middlewareface_middlewarecheck_middlewareget_middleware_chain_BUILTIN_PROVIDES)camel2under)uniquec           	          SSK Jn  [        X5      (       a  U R                  n [	        U S[	        U SS 5      5      nUc-  [        U R                  R                  5      R                  5       nU$ )Nr   )partial	func_name__name__)		functoolsr   
isinstancefuncgetattrr   	__class__r   lower)r   r   rets      _/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/face/command.py_get_default_namer#      sY    !$  yy $WT:t%D
EC
{$..11288:J    c                     U R                   nU(       d  g[        U5      n UR                  5        Vs/ s H  o3(       d  M  UPM     snS   nU$ s  snf ! [         a    Sn U$ f = f)N r   )__doc__r   
splitlines
IndexError)r   doc	unwrappedgr!   s        r"   _docstring_to_docr-   %   sk    
,,CC I#..060QAq06q9 J	 7 Js(   A 
AAA A A$#A$c                 .    [         R                  " U 5      $ N)r   err)msgs    r"   default_print_errorr2   3   s    88C=r$   c                      ^  \ rS rSrSrSU 4S jjr\S 5       rU 4S jrU 4S jr	S r
SU 4S jjrSS	 jrSS
 jrSS jrSrU =r$ )Command;   aa  The central type in the face framework. Instantiate a Command,
populate it with flags and subcommands, and then call
command.run() to execute your CLI.

Note that only the first three constructor arguments are
positional, the rest are keyword-only.

Args:
   func (callable): The function called when this command is
      run with an argv that contains no subcommands.
   name (str): The name of this command, used when this
      command is included as a subcommand. (Defaults to name
      of function)
   doc (str): A description or message that appears in various
       help outputs.
   flags (list): A list of Flag instances to initialize the
      Command with. Flags can always be added later with the
      .add() method.
   posargs (bool): Pass True if the command takes positional
      arguments. Defaults to False. Can also pass a PosArgSpec
      instance.
   post_posargs (bool): Pass True if the command takes
      additional positional arguments after a conventional '--'
      specifier.
   help (bool): Pass False to disable the automatically added
      --help flag. Defaults to True. Also accepts a HelpHandler
      instance, see those docs for more details.
   middlewares (list): A list of @face_middleware decorated
      callables which participate in dispatch. Also addable
      via the .add() method. See Middleware docs for more
      details.

c                   > Ub  UO
[        U5      nUc  [        U5      n[        [        U ]  X#UR                  SS 5      UR                  SS 5      UR                  SS 5      UR                  SS5      S9  UR                  S[        5      nXPl        [        5       U l	        XR                  S'   [        UR                  S	S 5      =(       d    / 5      n[        5       U l        / U R                  S'   [        5       U l        XR                  S'   U H  nU R                  U5        M     U(       a%  [        S
[        UR!                  5       5      -  5      eU(       ac  UR"                  (       a  U R%                  UR"                  5        UR&                  (       a&  U R%                  UR(                  UR&                  5        U(       d  U(       d  [+        SU-  5      eg )Nflagsposargspost_posargsflagfileT)r7   r8   r9   r:   help middlewaresz unexpected keyword arguments: %rzFCommand requires a handler function or help handler to be set, not: %r)r#   r-   superr4   __init__popDEFAULT_HELP_HANDLERhelp_handlerr   _path_func_maplist_path_mw_map_path_wrapped_mapadd_middleware	TypeErrorsortedkeysflagaddsubcmdr   
ValueError)	selfr   namer*   kwargs_helpr=   mwr   s	           r"   r?   Command.__init__]   s   't->t-D;#D)C 	gt%d,2JJw,E.4jjD.I39::nd3S/5zz*d/K	 	& 	M 

6#78! *m"&B6::mT:@bA'M ""!,%)r"B#  >AVVWWzz$||U\\2E 359: ; ; 	r$   c                      U R                   S   $ )Nr<   )rC   )rO   s    r"   r   Command.func   s    ""2&&r$   c                   > US   n[        U5      (       a  U R                  U5      $ US   n[        U[        5      (       d  [	        U5      (       d  Uc  [        U0 UD6n[        U[        5      (       a  U R                  U5        U$ US   n[        U[        5      (       d  [        U0 UD6n[        [        U ]#  U5        U$ )a  Add a flag, subcommand, or middleware to this Command.

If the first argument is a callable, this method contructs a
Command from it and the remaining arguments, all of which are
optional. See the Command docs for for full details on names
and defaults.

If the first argument is a string, this method constructs a
Flag from that flag string and the rest of the method
arguments, all of which are optional. See the Flag docs for
more options.

If the argument is already an instance of Flag or Command, an
exception is only raised on conflicting subcommands and
flags. See add_command for details.

Middleware is only added if it is already decorated with
@face_middleware. Use .add_middleware() for automatic wrapping
of callables.

r   )	r   rG   r   r4   callableadd_commandr   r>   rL   )rO   akwtargetrM   rK   r   s         r"   rL   Command.add   s    2 1  &&v..1&'**x/?/?6>a&2&Ffg&&V$Mt$%%>b>Dgt &r$   c                 \  > [        U[        5      (       d  [        SU-  5      eU R                  S   n[        [        U ]  U5        U R                   HV  nX0R                  ;  d  M  UR                  USS    U R                  U'   UR                  USS    nX$-   U R                  U'   MX     g)zAdd a Command, and all of its subcommands, as a subcommand of this
Command.

Middleware from the current command is layered on top of the
subcommand's. An exception may be raised if there are
conflicting middlewares or subcommand names.
z"expected Command instance, not: %rr<      N)r   r4   rH   rE   r>   rL   
subprs_maprC   )rO   rM   self_mwpathsub_mwr   s        r"   rY   Command.add_command   s     &'**@6IJJ##B'gt (OOD...,2,A,A$qr(,K##D),,T!"X6*1*:!!$'	 $
 	r$   c                    [        U5      (       d  [        U5      n[        U5        UR                   H  nU R	                  U5        M     U R
                  R                  5        H  u  p4U/U-   U R
                  U'   M     g)z{Add a single middleware to this command. Outermost middleware
should be added first. Remember: first added, first called.

N)r   r   r   _face_flagsrL   rE   items)rO   rS   rK   rb   mwss        r"   rG   Command.add_middleware   sr    
 R   $BNNDHHTN # **002ID')dSjDd# 3 	r$   c                 P  > [         [        U ]  XS9nU R                  U5      nSU;   d  SU;   a  [	        U5      $ [	        UR                  5        VVs/ s H@  u  pVUR                  U;   d(  X`R                  L d  X`R                  R                  L d  M=  XV4PMB     snn5      $ s  snnf )zCommand's get_flag_map differs from Parser's in that it filters
the flag map to just the flags used by the endpoint at the
associated subcommand *path*.
)rb   with_hiddenargs_flags_)
r>   r4   get_flag_mapget_dep_namesr   rg   rP   flagfile_flagrB   rK   )rO   rb   rk   flag_map	dep_nameskfr   s          r"   rn   Command.get_flag_map   s    
 $4$4X&&t,	i8y#8 x((x~~/? W/?tq166YCV $6$66!?P?P?U?U:U #QF/? W X 	X Ws   <B"
B"
c                    U R                   U   nU(       d  / $ U R                  U   n[        [        USS95      nU[        U5      0nU HQ  n[        [        USS95      nUR                   H  nXuU'   M	     UR
                  (       a  M@  UR                  U5        MS     [        U5      n	X   R                  U5      n
[        U
5      $ )zGet a list of the names of all required arguments of a command (and
any associated middleware).

By specifying *path*, the same can be done for any subcommand.
F)only_requiredT)
rC   rE   setr   _face_provides_face_optionalupdater   unionrI   )rO   rb   r   rh   required_argsdep_maprS   	arg_namesproviderdep_maprecursive_required_argss              r"   ro   Command.get_dep_names   s     ""4(I% M$eDE]+,BM"DABI,,#,  -$$$$$Y/   ("*."6"6}"E-..r$   c           
      |   Uc  U R                   R                  5       nU GHX  nU R                   U   nUc  M  U(       a  U R                  U   OU n/ nUR                  R                  (       a  XTR                  R                  /-  nUR
                  R                  (       a  XTR
                  R                  /-  nU R                  U5      nU R                  US9 Vs/ s H  owR                  PM     nnU R                  U   n	U	 V
Vs/ s H@  oR                  (       a+  U
R                   Vs/ s H  oU;   d  M
  UPM     sn(       d  M>  U
PMB     nn
nU[        U-   -  n [        XU5      nXR                   U'   GM[     gs  snf s  snf s  snn
f ! [         a#  nUR                  S   SU< S3-   4Ul        e SnAff = f)a  Compile and validate one or more subcommands to ensure all
dependencies are met. Call this once all flags, subcommands,
and middlewares have been added (using .add()).

This method is automatically called by .run() method, but it
only does so for the specific subcommand being invoked. More
conscientious users may want to call this method with no
arguments to validate that all subcommands are ready for
execution.
N)rb   r   z (in path: ))rC   rJ   r`   r8   providesr9   ro   	get_flagsrP   rE   rz   ry   r   r   	NameErrorargsrF   )rO   pathsrb   r   prsr   depsrt   
flag_namesall_mwsrS   prh   wrappednes                  r"   prepareCommand.prepare  s    ='',,.ED&&t,D|+/$//$'TCH{{##[[1122((--6677%%d+D*...d.*CD*CQ&&*CJD''-G !( C"/@/@"$"3"3A"3QDyq"3A C C)J66H.s(C
 ,3""4(5 8 	 E
 BC
  771:D(BBDsB   E>$F+	F8F>FFFF
F;F66F;c                 <   Ub  USL a  [         nO%U(       a  [        U5      (       d  [        SU-  5      eU(       a  [        U5      O0 nX4S'    U R	                  US9nUR                  UR                  5       5        U R(                  UR                      nUS   nUR                  (       av  U(       aO  UR                  (       a^  UR                  R                  UR                  R                  R                  5      (       a   [        UR                  R                  U5      $ U(       d  [+        S5      eU R-                  UR                   /S9  U R.                  R                  UR                   U5      n [        X5      nU$ ! [
         Ga_  nUR                  nUR                  5       S   nUR                  (       a  UR                  (       a  UR                  R                  UR                  R                  R                  5      (       aD  UR                  UR                  5       5        [        UR                  R                  U5      s SnA$ SUR                  =(       d    U R                  -   nUR                   (       a*  USSR#                  UR                   =(       d    S	5      -   -  nUR$                  S
   n	U	(       a  USU	-   -  n['        U5      n
U(       a  U" U5        U
eSnAff = f! [0         a#  nU(       a  U" UR3                  5       5        e SnAff = f)a  Parses arguments and dispatches to the appropriate subcommand
handler. If there is a parse error due to invalid user input,
an error is printed and a CommandLineError is raised. If not
caught, a CommandLineError will exit the process, typically
with status code 1. Also handles dispatching to the
appropriate HelpHandler, if configured.

Defaults to handling the arguments on the command line
(``sys.argv``), but can also be explicitly passed arguments
via the *argv* parameter.

Args:
   argv (list): A sequence of strings representing the
      command-line arguments. Defaults to ``sys.argv``.
   extras (dict): A map of additional arguments to be made
      available to the subcommand's handler function.
   print_error (callable): The function that formats/prints
       error messages before program exit on CLI errors.

.. note::

   For efficiency, :meth:`run()` only checks the subcommand
   invoked by *argv*. To ensure that all subcommands are
   configured properly, call :meth:`prepare()`.

NTz)expected callable for print_error, not %rprint_error_)argvsubcommand_zerror:  r<   r   z: z2expected command handler or help handler to be set)r   )r2   rX   rH   dictparser   prs_resto_cmd_scoperB   r7   getrK   rP   r{   r   r   subcmdsjoinr   r	   rC   RuntimeErrorr   rF   r
   format_message)rO   r   extrasprint_errorrQ   r   apecmdr1   e_msgcler   r   r!   ues                  r"   runCommand.runE  s{   6 +"5-K+!6!6G)* + + "(fR!,~	jjdj+G0 	g**,- ""7??3]#Tgmm@Q@QRURbRbRgRgRlRl@m@m#**//88STTGOO,-((,,W__dC	)C
 
W " 	kkG &&(7CGMMgmm6G6GHXHXH]H]HbHb6c6cg2245c..33V<<w||8tyy9CsSXXgoo&;<<< HHQKEte|#"3'CC I+	N  	B--/0	s>   F 4K. K+B=K&	K+BK&&K+.
L8LL)rC   rE   rF   rB   )NN)r<   T)r<   r/   )NNN)r   
__module____qualname____firstlineno__r'   r?   propertyr   rL   rY   rG   rn   ro   r   r   __static_attributes____classcell__)r   s   @r"   r4   r4   ;   sP     B)V ' '+Z(&X4/:,\Q Qr$   r4   )#
__future__r   syscollectionsr   
face.utilsr   r   r   face.errorsr   r	   r
   face.parserr   r   face.helpersr   face.middlewarer   r   r   r   r   r   r   boltons.strutilsr   boltons.iterutilsr   r#   r-   r2   rA   r4   r<   r$   r"   <module>r      s^    % 
 # 6 6 H H $ $0 0 0 ) $ #} [f [r$   