
    hD                    v    S SK Jr  S SKJrJrJrJrJrJr  S SK	r	S SK
JrJr  S SKJr  \" S\S9r " S S	5      rg)
    )annotations)AnyCallableDictSequenceTypeVaroverloadN)delimeter_contextswap_delimeters)ConstructorRegistry	CallableT)boundc            
          \ rS rSrSrSS jr\SS j5       r\ SSS.     SS jjj5       r SSS.     SS jjjrSSSS	S
S
SS	SS.	                   SS jjrSr	g)SubcommandApp   a   This class provides a decorator-based API for subcommands in
:mod:`tyro`, inspired by click. Under-the-hood, this is a light wrapper
over :func:`tyro.cli`.

Example:

.. code-block:: python

    from tyro.extras import SubcommandApp

    app = SubcommandApp()

    @app.command
    def greet(name: str, loud: bool = False):
        '''Greet someone.'''
        greeting = f"Hello, {name}!"
        if loud:
            greeting = greeting.upper()
        print(greeting)

    @app.command(name="addition")
    def add(a: int, b: int):
        '''Add two numbers.'''
        print(f"{a} + {b} = {a + b}")

    if __name__ == "__main__":
        app.cli()

Usage:

.. code-block:: bash

    python my_script.py greet Alice
    python my_script.py greet Bob --loud
    python my_script.py addition 5 3

c                    0 U l         g N_subcommands)selfs    U/home/james-whalen/.local/lib/python3.13/site-packages/tyro/extras/_subcommand_app.py__init__SubcommandApp.__init__3   s
    13    c                    g r    )r   funcs     r   commandSubcommandApp.command6   s    58r   N)namec                   g r   r   )r   r   r    s      r   r   r   9   s     ,/r   c               2   ^ ^ SUU 4S jjnUb  U" U5      $ U$ )ax  A decorator to register a function as a subcommand.

This method is inspired by Click's ``@cli.command()`` decorator.
It adds the decorated function to the list of subcommands.

Args:
    func: The function to register as a subcommand. If None, returns a
        function to use as a decorator.
    name: The name of the subcommand. If None, the name of the function is used.
c                D   > Tc  U R                   mU TR                  T'   U $ r   )__name__r   )r   r    r   s    r   inner$SubcommandApp.command.<locals>.innerR   s&    |}}&*Dd#Kr   r   r   returnr   r   )r   r   r    r%   s   ` ` r   r   r   A   s$    "	 	 ;Lr   FT)	progdescriptionargsuse_underscoresconsole_outputsadd_helpconfigsort_subcommandsregistryc       	           U R                   c   eU(       a-  [        [        U R                   R                  5       S S95      n
OU R                   R	                  5       n
[        U(       a  SOS5         [        U
R                  5       5      nU H   nU
R                  U5      U
[        U5      '   M"     SSS5        [        R                  R                  U
UUUUUUUU	S9	$ ! , (       d  f       N3= f)a  Run the command-line interface.

This method creates a CLI using tyro, with all subcommands registered using
:func:`command()`.

Args:
    prog: The name of the program printed in helptext. Mirrors argument from
        `argparse.ArgumentParser()`.
    description: Description text for the parser, displayed when the --help flag is
        passed in. If not specified, the class docstring is used. Mirrors argument from
        `argparse.ArgumentParser()`.
    args: If set, parse arguments from a sequence of strings instead of the
        commandline. Mirrors argument from `argparse.ArgumentParser.parse_args()`.
    use_underscores: If True, use underscores as a word delimiter instead of hyphens.
        This primarily impacts helptext; underscores and hyphens are treated equivalently
        when parsing happens. We default helptext to hyphens to follow the GNU style guide.
        https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
    console_outputs: If set to `False`, parsing errors and help messages will be
        suppressed.
    add_help: Add a -h/--help option to the parser. This mirrors the argument from
        `argparse.ArgumentParser()`.
    config: Sequence of config marker objects, from `tyro.conf`.
    sort_subcommands: If True, sort the subcommands alphabetically by name.
    registry: A :class:`tyro.constructors.ConstructorRegistry` instance containing custom
        constructor rules.
Nc                    U S   $ )Nr   r   )xs    r   <lambda>#SubcommandApp.cli.<locals>.<lambda>   s	    qQRtr   )key_-)r)   r*   r+   r,   r-   r.   r/   r1   )r   dictsorteditemscopyr
   listkeyspopr   tyroextrassubcommand_cli_from_dict)r   r)   r*   r+   r,   r-   r.   r/   r0   r1   subcommandsorig_subcommand_names	orig_names                r   cliSubcommandApp.cli_   s    N   ,,, vd&7&7&=&=&?^TUK++002K os3?$()9)9);$<!2	:E//):TOI67 3 @
 {{33#++ 4 

 
	
 @?s   2A C
C-r   )r(   Noner'   r   )r   rI   r    
str | Noner(   z Callable[[CallableT], CallableT])r   zCallableT | Noner    rJ   r(   z,CallableT | Callable[[CallableT], CallableT])r)   rJ   r*   rJ   r+   zSequence[str] | Noner,   boolr-   rK   r.   rK   r/   zSequence[Any] | Noner0   rK   r1   zConstructorRegistry | Noner(   r   )
r$   
__module____qualname____firstlineno____doc__r   r	   r   rG   __static_attributes__r   r   r   r   r      s   $L4 8 8 /  	// 	/
 
*/ / "&  	 	
 
6B  "&%) % $'+!&/3?
 ?
  	?

 #?
 ?
 ?
 ?
 %?
 ?
 -?
 
?
 ?
r   r   )
__future__r   typingr   r   r   r   r   r	   rA   tyro._stringsr
   r   tyro.constructorsr   r   r   r   r   r   <module>rU      s/    " C C  < 1Kx0	R
 R
r   