
    =)i                    v   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mZ d dl	m	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZmZmZmZ d d
lmZ d dlZd dlmZ d dlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC ddlDmEZE ej                  ZGdZHdeIeJ   deJdee   ddfdZKdeLej                  ej                  f   fdZN G d d      ZOdeOde/fdZPdeOdej                  fdZRdeBdeSfd ZTdeBdeBfd!ZUd"eBd#eVd$eVd%e,de/f
d&ZWd'eSdeSfd(ZXd)eed*ef      deLeYeej                  ej                  f      e\eSef   eeS   f   fd+Z]d,e5d#eVd%e,dej                  fd-Z^d.edeeegef      fd/Z_dUd0eeS   dee   fd1Z`d2eIe   deegef   fd3Zad4eeegef      d5ee   deeee      geeYe      f   fd6Zbd7ee   deeeLed*f      geeLed*f      f   fd8Zcdg ddd9d)eed*ef      d:eej                     d;ee\eSeeSgef   f      d<eeS   d#eVdeed*ef      fd=Zdd>ed?e?dej                  fd@ZfdAedBee2eLe2d*f   f   deVfdCZgdDe@deLeej                  ej                  f   ef   fdEZhdddFd)eed*ef      d4eed*ef      deed*ef      fdGZi	 dUd)eed*ef      deed*ef      fdHZjdIeed*ef    edJ      f   ddfdKZkdeVfdLZldeVfdMZm	 	 dVdNeeS edO      f   dPeeV edQ      f   dReeV edS      f   denfdTZoy)W    N)Sequence)datetime)Enum)update_wrapper)Path)FrameSummaryStackSummary)TracebackType)	AnnotatedAnyCallableOptionalUnion)UUID)Doc)TyperChoice   )get_args
get_originis_literal_typeis_unionliteral_values)!get_completion_inspect_parameters)DEFAULT_MARKUP_MODEHAS_RICH
MarkupModeTyperArgumentTyperCommand
TyperGroupTyperOption)AnyTypeArgumentInfoCommandFunctionTypeCommandInfoDefaultDefaultPlaceholderDeveloperExceptionConfigFileBinaryReadFileBinaryWriteFileTextFileTextWriteNoneType
OptionInfoParameterInfo	ParamMetaRequired	TyperInfo	TyperPath)get_params_from_function__typer_developer_exception__exc_type	exc_valuetbreturnc           	         t        |t        d       }t        j                  dt        j                  d            }|s|r|j                  st        | ||       y t        j                  j                  t              }t        j                  j                  t        j                        }||g}|}t        r=ddlm}	 |	j                  |||      }
|	j                  d      }|j                  |
       y t         j"                  j%                  |      }g }|j&                  D ]{  t)        fd|D              rT|j*                  r$|j-                  t!        j.                  j0                  j2                  j4                  d	             k|j-                         } t7        j8                  |      }||_        |j;                         D ]  }t        |t<        j>                  
        y )NTYPER_STANDARD_TRACEBACK_TYPER_STANDARD_TRACEBACKr   )
rich_utilsT)stderrc              3   T   K   | ]  }j                   j                  |       ! y wN)filename
startswith).0pathframes     '/mnt/e/genesis-system/lib/typer/main.py	<genexpr>zexcept_hook.<locals>.<genexpr>Y   s      N4u~~((.Ns   %( )r@   linenonameline)file) getattr$_typer_developer_exception_attr_nameosgetenvpretty_exceptions_enable_original_except_hookrC   dirname__file__clickr   rG   r<   get_traceback_get_rich_consoleprint	tracebackTracebackExceptionfrom_exceptionstackanypretty_exceptions_shortappendr   r@   rH   rI   r	   	from_listformatsysr=   )r5   r6   r7   exception_configstandard_traceback
typer_path
click_pathinternal_dir_namesexcr<   rich_tbconsole_stderrtb_excr[   final_stack_summaryrJ   rD   s                   @rE   except_hookrl   ;   s    ?F7? "BII.I$J 	88h	26*J0J$j1
C **30@BTU#55T5BW%))88=F "E  N;MNN#;;**!&$||"ZZ	 LL  '007&FL %d$%
    c                  \    t               \  } }t        |       \  }}t        |      \  }}||fS r?   )r   get_click_param)install_param
show_paramclick_install_param_click_show_params        rE    get_install_completion_argumentsru   n   s;     A CM:,];)*5a 000rm   c            3          e Zd ZdZ ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed      de ed      ddddddeee    e	d      f   d	eee
e       e	d
      f   dee e	d      f   dee e	d      f   deee    e	d      f   dee e	d      f   deeedef       e	d      f   deeeeef       e	d      f   deeedef       e	d      f   deee    e	d      f   deee    e	d      f   deee    e	d      f   d ee e	d!      f   d"ee e	d#      f   d$ee e	d%      f   d&ee e	d'      f   d(ee e	d)      f   d*ee e	d+      f   d,eeedf    e	d-      f   d.ee e	d/      f   d0ee e	d1      f   d2ee e	d3      f   d4ee e	d5      f   f.d6Z ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed      d7d	eee
e       e	d8      f   dee e	d9      f   dee e	d:      f   deee    e	d      f   dee e	d      f   deeedef       e	d      f   deeeeef       e	d;      f   deee    e	d<      f   deee    e	d=      f   deee    e	d>      f   d eee    e	d?      f   d"ee e	d#      f   d$ee e	d@      f   d&ee e	dA      f   d,eeedf    e	dB      f   dCeegef   f dDZ	 dUddddd ed      dddd ed      dEdeee    e	dF      f   d	eee
e       e	dG      f   deeeeef       e	d;      f   deee    e	d<      f   deee    e	d=      f   deee    e	d>      f   d eee    e	d?      f   d"ee e	d#      f   dee e	d:      f   d$ee e	d@      f   d&ee e	dH      f   d,eeedf    e	dB      f   dCeegef   fdIZ ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed       ed      d ed      dJdKd deee    e	dL      f   d	eee
e       e	dM      f   dee e	d9      f   dee e	d:      f   deee    e	d      f   dee e	d      f   deeedef       e	d      f   deeeeef       e	d;      f   deeedef       e	dN      f   deee    e	dO      f   deee    e	d=      f   deee    e	d>      f   d eee    e	d?      f   d"ee e	d#      f   d$ee e	d@      f   d&ee e	dH      f   d,eeedf    e	dB      f   dCdf&dPZdQedRedCefdSZdedCefdTZy)VTyperz
    `Typer` main class, the main entrypoint to use Typer.

    Read more in the
    [Typer docs for First Steps](https://typer.tiangolo.com/tutorial/typer-app/).

    ## Example

    ```python
    import typer

    app = typer.Typer()
    ```
    NFz	[OPTIONS]T)rI   clsinvoke_without_commandno_args_is_helpsubcommand_metavarchainresult_callbackcontext_settingscallbackhelpepilog
short_helpoptions_metavaradd_help_optionhidden
deprecatedadd_completionrich_markup_moderich_help_panelsuggest_commandsrP   pretty_exceptions_show_localsr]   rI   a  
                The name of this application.
                Mostly used to set the name for [subcommands](https://typer.tiangolo.com/tutorial/subcommands/), in which case it can be overridden by `add_typer(name=...)`.

                **Example**

                ```python
                import typer

                app = typer.Typer(name="users")
                ```
                rx   a  
                The class of this app. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
                Otherwise, should be a subtype of `TyperGroup`.

                **Example**

                ```python
                import typer

                app = typer.Typer(cls=TyperGroup)
                ```
                ry   a3  
                By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.

                **Example**

                ```python
                import typer

                app = typer.Typer(invoke_without_command=True)
                ```
                rz   a,  
                If this is set to `True`, running a command without any arguments will automatically show the help page.

                **Example**

                ```python
                import typer

                app = typer.Typer(no_args_is_help=True)
                ```
                r{   z
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                How to represent the subcommand argument in help.
                r|   z
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                Allow passing more than one subcommand argument.
                r}   .a	  
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                A function to call after the group's and subcommand's callbacks.
                r~   a  
                Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
                Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).

                **Example**

                ```python
                import typer

                app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
                ```
                r   a  
                Add a callback to the main Typer app. Can be overridden with `@app.callback()`.
                See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/commands/callback/) for more details.

                **Example**

                ```python
                import typer

                def callback():
                    print("Running a command")

                app = typer.Typer(callback=callback)
                ```
                r   a  
                Help text for the main Typer app.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
                and which one takes priority.

                **Example**

                ```python
                import typer

                app = typer.Typer(help="Some help.")
                ```
                r   a  
                Text that will be printed right after the help text.

                **Example**

                ```python
                import typer

                app = typer.Typer(epilog="May the force be with you")
                ```
                r   a  
                A shortened version of the help text that can be used e.g. in the help table listing subcommands.
                When not defined, the normal `help` text will be used instead.

                **Example**

                ```python
                import typer

                app = typer.Typer(help="A lot of explanation about user management", short_help="user management")
                ```
                r   a  
                In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
                Set `options_metavar` to change this into a different string.

                **Example**

                ```python
                import typer

                app = typer.Typer(options_metavar="[OPTS]")
                ```
                r   a%  
                **Note**: you probably shouldn't use this parameter, it is inherited
                from Click and supported for compatibility.

                ---

                By default each command registers a `--help` option. This can be disabled by this parameter.
                r   z
                Hide this command from help outputs. `False` by default.

                **Example**

                ```python
                import typer

                app = typer.Typer(hidden=True)
                ```
                r   a
  
                Mark this command as being deprecated in the help text. `False` by default.

                **Example**

                ```python
                import typer

                app = typer.Typer(deprecated=True)
                ```
                r   aQ  
                Toggle whether or not to add the `--install-completion` and `--show-completion` options to the app.
                Set to `True` by default.

                **Example**

                ```python
                import typer

                app = typer.Typer(add_completion=False)
                ```
                r   a8  
                Enable markup text if you have Rich installed. This can be set to `"markdown"`, `"rich"`, or `None`.
                By default, `rich_markup_mode` is `None` if Rich is not installed, and `"rich"` if it is installed.
                See [the tutorial on help formatting](https://typer.tiangolo.com/tutorial/commands/help/#rich-markdown-and-markup) for more information.

                **Example**

                ```python
                import typer

                app = typer.Typer(rich_markup_mode="rich")
                ```
                r   a  
                Set the panel name of the command when the help is printed with Rich.

                **Example**

                ```python
                import typer

                app = typer.Typer(rich_help_panel="Utils and Configs")
                ```
                r   a  
                As of version 0.20.0, Typer provides [support for mistyped command names](https://typer.tiangolo.com/tutorial/commands/help/#suggest-commands) by printing helpful suggestions.
                You can turn this setting off with `suggest_commands`:

                **Example**

                ```python
                import typer

                app = typer.Typer(suggest_commands=False)
                ```
                rP   a  
                If you want to disable [pretty exceptions with Rich](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-with-rich),
                you can set `pretty_exceptions_enable` to `False`. When doing so, you will see the usual standard exception trace.

                **Example**

                ```python
                import typer

                app = typer.Typer(pretty_exceptions_enable=False)
                ```
                r   a  
                If Rich is installed, [error messages](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-and-errors)
                will be nicely printed.

                If you set `pretty_exceptions_show_locals=True` it will also include the values of local variables for easy debugging.

                However, if such a variable contains delicate information, you should consider leaving `pretty_exceptions_show_locals=False`
                (the default) to `False` to enhance security.

                **Example**

                ```python
                import typer

                app = typer.Typer(pretty_exceptions_show_locals=True)
                ```
                r]   a  
                By default, [pretty exceptions formatted with Rich](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-with-rich) hide the long stack trace.
                If you want to show the full trace instead, you can set the parameter `pretty_exceptions_short` to `False`:

                **Example**

                ```python
                import typer

                app = typer.Typer(pretty_exceptions_short=False)
                ```
                c                   || _         || _        || _        || _        || _        || _        || _        t        di d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|| _        g | _	        g | _
        d | _        y )NrI   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r    )_add_completionr   r   r   rP   r   r]   r1   inforegistered_groupsregistered_commandsregistered_callback)selfrI   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r]   s                           rE   __init__zTyper.__init__   s    B  .,<. 0(@%-J*'>$ 


 $:
 ,	

  2
 
 ,
 .
 
 
 
 "
 ,
 ,
 
  "!
	$ 3568 8< rm   )rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   a  
                The class of this app. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
                Otherwise, should be a subtype of `TyperGroup`.
                z
                By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
                z
                If this is set to `True`, running a command without any arguments will automatically show the help page.
                a  
                Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
                Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
                a  
                Help text for the command.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
                and which one takes priority.
                zV
                Text that will be printed right after the help text.
                z
                A shortened version of the help text that can be used e.g. in the help table listing subcommands.
                When not defined, the normal `help` text will be used instead.
                a  
                In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
                Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
                zZ
                Hide this command from help outputs. `False` by default.
                zg
                Mark this command as deprecated in the help text. `False` by default.
                zg
                Set the panel name of the command when the help is printed with Rich.
                r8   c                h    	
 dt         dt         f	 
fd}|S )a  
        Using the decorator `@app.callback`, you can declare the CLI parameters for the main CLI application.

        Read more in the
        [Typer docs for Callbacks](https://typer.tiangolo.com/tutorial/commands/callback/).

        ## Example

        ```python
        import typer

        app = typer.Typer()
        state = {"verbose": False}

        @app.callback()
        def main(verbose: bool = False):
            if verbose:
                print("Will write verbose output")
                state["verbose"] = True

        @app.command()
        def delete(username: str):
            # define subcommand
            ...
        ```
        fr8   c                     t        di dd	d
ddddd| d	d
ddxs j                  d      dddd_        | S )Nrx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   )r1   _info_val_strr   )r   r   r|   rx   r~   r   r   r   r   ry   rz   r   r}   r   r   r   r{   s    rE   	decoratorz!Typer.callback.<locals>.decorator  s    '0 (('=( !0( $6	(
 ( !0( "2( ( ( ( &( $Lt'9'9:K'L( !0(  !(" &#($ !0%(D$( Hrm   )r#   )r   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   s   ```````````````` rE   r   zTyper.callback#  s,    f	, 	1D 	 	 	. rm   )rx   r~   r   r   r   r   r   rz   r   r   r   z;
                The name of this command.
                a  
                The class of this command. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
                Otherwise, should be a subtype of `TyperCommand`.
                zj
                Mark this command as deprecated in the help outputs. `False` by default.
                c                l    	
 t         dt        dt        f
	 fd}|S )a  
        Using the decorator `@app.command`, you can define a subcommand of the previously defined Typer app.

        Read more in the
        [Typer docs for Commands](https://typer.tiangolo.com/tutorial/commands/).

        ## Example

        ```python
        import typer

        app = typer.Typer()

        @app.command()
        def create():
            print("Creating user: Hiro Hamada")

        @app.command()
        def delete():
            print("Deleting user: Hiro Hamada")
        ```
        r   r8   c                     j                   j                  t        | 
xs j                  d      	             | S )Nr   )rI   rx   r~   r   r   r   r   r   r   rz   r   r   r   )r   r^   r$   r   )r   r   rx   r~   r   r   r   r   rI   rz   r   r   r   r   s    rE   r   z Typer.command.<locals>.decoratorx  s^    $$++%5!)'P4+=+=>O+P$3$3!)$3!( Hrm   )r   r#   )r   rI   rx   r~   r   r   r   r   r   rz   r   r   r   r   s   ````````````` rE   commandzTyper.command  s8    L ;C	, 	1D 	 	 	. rm   )rI   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   typer_instancea  
                The name of this subcommand.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's name,
                and which one takes priority.
                a  
                The class of this subcommand. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
                Otherwise, should be a subtype of `TyperGroup`.
                z
                Add a callback to this app.
                See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/commands/callback/) for more details.
                a  
                Help text for the subcommand.
                See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
                and which one takes priority.
                c          
          | j                   j                  t        |fi d|d|d|d|d|d|d|d|	d	|
d
|d|d|d|xs | j                  d      d|d|d|d|       y)a0  
        Add subcommands to the main app using `app.add_typer()`.
        Subcommands may be defined in separate modules, ensuring clean separation of code by functionality.

        Read more in the
        [Typer docs for SubCommands](https://typer.tiangolo.com/tutorial/subcommands/add-typer/).

        ## Example

        ```python
        import typer

        from .add import app as add_app
        from .delete import app as delete_app

        app = typer.Typer()

        app.add_typer(add_app)
        app.add_typer(delete_app)
        ```
        rI   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   N)r   r^   r1   r   )r   r   rI   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   s                      rE   	add_typerzTyper.add_typer  s    B 	%%  (>	
 !0 $6  !0 "2 "   & $Lt'9'9:K'L" !0#$ %& &'( !0)	
rm   argskwargsc           
         t         j                  t        k7  rt        t         _        	  t        |       |i |S # t        $ rB}t        |t        t        | j                  | j                  | j                               |d }~ww xY w)N)rP   r   r]   )ra   
excepthookrl   get_command	ExceptionsetattrrM   r'   rP   r   r]   )r   r   r   es       rE   __call__zTyper.__call__k  s{    >>[((CN	$;t$d5f55 	 4(-1-J-J262T2T,0,H,H G!	s   9 	B=A??Bc                     t        | j                  |      }t        |t              r|j                  n|}t        |t
              sJ |S r?   )rL   r   
isinstancer&   valuestr)r   rI   valval_strs       rE   r   zTyper._info_val_str  s<    dii&)#/AB#))'3'''rm   r?   )__name__
__module____qualname____doc__r%   r   r   r   r   r   typer   boolr   r   dictr   r   r   r#   r   r   r   r   r   r   r   rm   rE   rw   rw   u   s   D DM" DM  EN  EN DM EN DM$ DM( DM$ DM  DM" DM" K  DM  EN  EN" &    DM" " , " \= SM
\=( T*%&
)\=J !*
!
K\=j #

k\=J &SM	

K\=d 	

e\=~ #Xc3h'(	

\=Z $T#s(^$
[\=| Xc3h'(
}\=d SM
e\=H SM

I\=h SM
i\=J #
K\=l #	

m\=F 

G\=f 

g\=F "
G\=j $
k\=N	 ##t)

O	\=n	 $
o	\=P
 #,#
Q
\=r
 (1(
s
\=^ "+"
_\=R DM EN EN DM EN DM DM DM DM DM DM DM EN EN DMmJ T*%&
J !*!
J( #
)J8 &SM	

9JR 	

SJl #Xc3h'(	

mJH $T#s(^$
IJZ SM	
[Jn SM
oJ~ SM
JP #SM
QJb #	

cJ| 
}JL 
MJ^ ##t)
_Jn 
&')<<	=oJj `&      DM     DM]`SM
` T,'(
`( $T#s(^$
)`: SM	
;`N SM
O`^ SM
_`p #SM
q`B #	

C`\ #
]`l 
m`| 
}`N ##t)
O`^ 
&')<<	=_`^ DM DM EN EN DM EN DM DM DM DM DM DM DM DM EN  DMUX
X
 SM	
	X
 T*%&
X
. !*!
/X
> #
?X
N &SM	

OX
h 	

iX
B #Xc3h'(	

CX
^ $T#s(^$
_X
p Xc3h'(
qX
B SM	
CX
V SM
WX
f SM
gX
x #SM
yX
J #	

KX
d 
eX
t 
uX
F ##t)
GX
V 
WX
tc S S .# # rm   rw   r   c                 r    t        t        |       | j                  | j                  | j                        }|S )Nr]   r   r   )get_group_from_infor1   r]   r   r   )r   groups     rE   	get_groupr     s6    .! . F F'88'88	E Lrm   c                 $   | j                   rt               \  }}| j                  s:| j                  j                  s$| j
                  st        | j                        dkD  rOt        |       }| j                   r6|j                  j                         |j                  j                         |S t        | j                        dk(  r| j                  d   }|j                  s?t        | j                  j                  t              s| j                  j                  |_        t        || j                  | j                         }| j                   r6|j                  j                         |j                  j                         |S t#        d      )Nr   r   )r]   r   z/Could not get a command for this Typer instance)r   ru   r   r   r   r   lenr   r   paramsr^   r~   r   r&   get_command_from_infor]   r   RuntimeError)r   rr   rt   click_commandsingle_commands        rE   r   r     sX   %%0P0R--**''++~112Q6 (1'@))  ''(;<  ''(89	^//	0A	5';;A>..z002D8
 /=.A.A.R.RN+-$2$J$J+<<

 ))  ''(;<  ''(89
9 rm   
typer_infoc                 f   t        | j                  t              s#t        j                  | j                  xs d      S | j
                  r_| j
                  j                  rI| j
                  j                  j                  }t        |t              st        j                  |xs d      S | j
                  r_| j
                  j                  rI| j
                  j                  j                  }t        |t              st        j                  |xs d      S | j                  r#t        j                  | j                        }|r|S | j
                  rc| j
                  j                  rM| j
                  j                  j                  }t        |t              st        j                  |xs d      }|r|S | j
                  r_| j
                  j                  rI| j
                  j                  j                  }t        |t              st        j                  |      }|r|S | j                  j                  S )NrG   )r   r   r&   inspectcleandocr   r   r   r   getdocr   )r   callback_helpinstance_helpdocr   instance_callbacks         rE   solve_typer_info_helpr     s   joo'9:
 5266  Z%>%>%R%R"11EEJJ-);<##M$7R88  Z%>%>%C%C"1166;;-);<##M$7R88nnZ001J  Z%>%>%R%R,,@@II($67..R0C
  Z%>%>%C%C&55::CC+-?@..!23C
??   rm   c                    i }| j                   j                         D ]  \  }}t        |t              s|||<   	 t	        | j
                  j                  |      }t        |t              s|||<   S	 	 t	        | j
                  j                  |      }t        |t              s|||<   	 |j                  ||<    t        |       |d<   t        di |S # t        $ r Y mw xY w# t        $ r Y Dw xY w)Nr   r   )__dict__itemsr   r&   rL   r   r   AttributeErrorr   r   r   r1   )r   valuesrI   r   callback_valueinstance_values         rE   solve_typer_info_defaultsr     s   F!**002 #e%!34 F4L		$))==N n.@A-t B		$))..N n.@A-t B {{t9#: +:6F6Nv!  		  		s#   5C25C"	CC"	C.-C.
group_infor]   r   r   c                r   | j                   sJ d       i }| j                   j                  D ],  }t        |||      }|j                  s|||j                  <   . | j                   j                  D ]w  }t        ||||      }|j                  r|||j                  <   .|j                  rdd l}	|	j                  dd       |j                  j                         D ]
  \  }
}|||
<    y t        |       }t        |j                        \  }}}|j                  xs t        }t        |t              sJ | dt                 |di d	|j                  xs d
d|d|j                   d|j"                  d|j$                  d|j&                  d|j(                  d|j*                  dt-        |j                  ||||      d|d|j.                  d|j0                  d|j2                  d|j4                  d|j6                  d|j8                  d|j:                  d|d|j<                  d|}|S ) Nz4A Typer instance is needed to generate a Click Group)command_infor]   r   r   r   zXThe 'callback' parameter is not supported by Typer when using `add_typer` without a name   )
stacklevelz should be a subclass of rI   rG   commandsry   rz   r{   r|   r}   r~   r   r   r   
convertorscontext_param_namer]   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   rI   r   r   r   warningswarnr   r   r   2get_params_convertors_ctx_param_name_from_functionrx   r   
issubclassry   rz   r{   r|   r}   r~   get_callbackr   r   r   r   r   r   r   r   )r   r]   r   r   r   r   r   sub_group_info	sub_groupr   sub_command_namesub_commandsolved_infor   r   r   rx   r   s                     rE   r   r     s    $$ >$ *,H"11EE -'%$;-

 <<%,HW\\"- %33EE 9'$;--	
	 >>'0HY^^$!!n    2;1C1C1I1I1K 9- +-8)*9#9& ,J7K
 	;;;O;OP	
//
'ZCc:&U3%/H(UU& #  +AA $33	
 '99  $33 %55  ))!1$;
  !" #$ !!%& ))'( $33)* $33+, !!-. ))/0 *14 $3356 *7E: Lrm   rI   c                 B    | j                         j                  dd      S )Nrs   -)lowerreplace)rI   s    rE   get_command_namer   O  s    ::<S))rm   r   .c                     g }i }d }| rpt        |       }|j                         D ]R  \  }}t        |j                  t        j
                        r|}-t        |      \  }}|r|||<   |j                  |       T |||fS r?   )r3   r   lenient_issubclass
annotationrT   Contextro   r^   )	r   r   r   r   
parameters
param_nameparamclick_param	convertors	            rE   r   r   S  s     FJ-h7
!+!1!1!3 	'J!%"2"2EMMB%/"%4U%;"K)2
:&MM+&	' :111rm   r   c                v   | j                   sJ d       | j                  xs t        | j                   j                        }| j                  }| t        j                  | j                         }nt        j                  |      }t        | j                         \  }}}| j                  xs t        } ||| j                  t        | j                   ||||      ||| j                  | j                  | j                  | j                   | j"                  | j$                  | j&                  || j(                        }	|	S )Nz'A command must have a callback functionr   )rI   r~   r   r   r   r   r   r   r   rz   r   r   r   r   )r   rI   r   r   r   r   r   r   r   rx   r   r~   r   r   r   r   r   rz   r   r   r   )
r   r]   r   rI   use_helpr   r   r   rx   r   s
             rE   r   r   f  s+      K"KK P 01F1F1O1O PD  H>>,"7"78##H-
 	;<;P;PQ	



*lC%66!**!1$;
 ""**$44$44$44""**)$44+G. Nrm   type_c                 l    d }t        | t              rt        }t        | t              rt	        |       }|S r?   )r   r   param_path_convertorr   generate_enum_convertor)r   r   s     rE   determine_type_convertorr     s0    04I%&(	%&+E2	rm   r   c                 B    | t        | t              r| S t        |       S y r?   )r   r   )r   s    rE   r   r     s%     #5$/u@T%[@rm   enumc                       D ci c]  }t        |j                        | c}dt        dt        f fd}|S c c}w )Nr   r8   c                 D    | t        |       }|v r|   } |      S y y r?   )r   )r   r   keyr   val_maps      rE   r   z*generate_enum_convertor.<locals>.convertor  s6    e*Cg~clCy   rm   )r   r   r   )r   r   r   r  s   `  @rE   r   r     s@    .23ss399~s"3G! ! !  4s   <r   default_valuec                 h     dt         t        t              dt         t        t              f fd}|S )Nr   r8   c                 h    | t        |       dk(  ry | D cg c]  }r |      n| c}S c c}w )Nr   )r   )r   vr   r  s     rE   internal_convertorz3generate_list_convertor.<locals>.internal_convertor  s9    M}4Uq:?@Q		!q0@@@s   /)r   r   r   list)r   r  r  s   `` rE   generate_list_convertorr    s3    A(8C="9 AhtCy>Q A
 rm   typesc                     | D cg c]  }t        |       c}dt        t        t        df      dt        t        t        df      ffd}|S c c}w )N
param_args.r8   c                 B    | y t        d t        |       D              S )Nc              3   :   K   | ]  \  }}|r ||      n|  y wr?   r   )rB   r   args      rE   rF   zGgenerate_tuple_convertor.<locals>.internal_convertor.<locals>.<genexpr>  s'      
 C (IcNS0
s   )tuplezip)r  r   s    rE   r  z4generate_tuple_convertor.<locals>.internal_convertor  s/      
$'
J$?
 
 	
rm   )r   r   r  r   )r	  r   r  r   s      @rE   generate_tuple_convertorr    sZ     @EEe*51EJ
U38_-
	%S/	"
  Fs   A)r   r   r   r   r   r   r   c                     	
 |xs i 	 sy t               }i 
|D ]  }d 
|<   	 |D ](  }|j                  s|j                  
|j                  <   * dt        dt        f 	
fd}t	        |        |S )Nr   r8   c                      }| j                         D ]  \  }}|v r |   |      |<   ||<    rt        j                         <    di S Nr   )r   rT   get_current_context)	r   _rich_traceback_guardkr  r   r   r]   use_convertors
use_paramss	       rE   wrapperzget_callback.<locals>.wrapper  so     7LLN 	"DAqN" 1q 1! 4
1 !
1		"
 -2-F-F-HJ)*%*%%rm   )r3   rI   defaultr   r   )r   r   r   r   r]   r   r   r   r  r  r  s   `  ``    @@rE   r   r     s      %2N)(3J!#J  &
!%
:& 3::%*]]Juzz"3	&# 	&# 	& 	& 7H%Nrm   r   parameter_infoc           
         |j                   |j                   S |j                  )t        j                  j	                  |j                        S | t
        u rt        j                  S | t        u r|j                  |j                  hd }d }|j                  t        |j                        }|j                  t        |j                        }t        j                  |||j                        S t        j                  S | t        u r^|j                  |j                  6t        j                  |j                  |j                  |j                        S t        j                  S | t         u rt        j"                  S | t$        k(  rt        j$                  S | t&        k(  r t        j(                  |j*                        S | t,        k(  s$|j.                  s|j0                  s|j2                  rct5        |j6                  |j8                  |j:                  |j<                  |j>                  |j2                  |j.                  |j0                        S tA        | tB              rPt        jD                  |jF                  xs d|jH                  |jJ                  |jL                  |jN                        S tA        | tP              rPt        jD                  |jF                  xs d|jH                  |jJ                  |jL                  |jN                        S tA        | tR              rPt        jD                  |jF                  xs d|jH                  |jJ                  |jL                  |jN                        S tA        | tT              rPt        jD                  |jF                  xs d|jH                  |jJ                  |jL                  |jN                        S tA        | tV              r/tY        | D cg c]  }|jZ                   c}|j\                  	      S t_        |       r*t        j`                  tc        |       |j\                  	      S te        d
|        c c}w )N)minmaxclamp)formats)exists	file_okaydir_okaywritablereadableresolve_path
allow_dash	path_typew)modeencodingerrorslazyatomicrrbwb)case_sensitivezType not yet supported: )3
click_typeparserrT   r	  FuncParamTyper   STRINGintr  r  IntRanger   INTfloat
FloatRangeFLOATr   BOOLr   r   DateTimer!  r   r(  r)  r'  r2   r"  r#  r$  r%  r&  r   r+   Filer+  r,  r-  r.  r/  r*   r(   r)   r   r   r   r3  r   Choicer   r   )r   r  min_max_items        rE   get_click_typerE    s      ,(((				*{{(()>)>??	s	||	s	)^-?-?-KDD!!->--.!!->--.>>dN<P<PQQ99	u	)^-?-?-K##"&&"&&$**  ;;	t	zz	t	zz	x	~~n&<&<==d$$##&&!(($..#,,#,,#,,'44%00$..	
 		
 
J	6zz$$+#,,!(($$!((
 	
 
J	1zz$$+#,,!(($$!((
 	
 
J	7zz$$,#,,!(($$!((
 	
 
J	8zz$$,#,,!(($$!((
 	
 
J	- $./DTZZ/)88
 	
 
	$||:&)88
 	
 1*>
?? 0s   'Qrx   class_or_tuplec                 >    t        | t              xr t        | |      S r?   )r   r   r   )rx   rF  s     rE   r   r   W  s     c4 DZ^%DDrm   r   c           	      |	   d }d}t        | j                  t              r/| j                  }|j                  t        k(  rd}n[|j                  }nN| j                  t        k(  s| j                  | j                  u rd}t               }n| j                  }t               }| j                  | j                  ur| j                  }nt        }|}d}d}d }d }	t        |      }
|
t        |
      rQg }t        |      D ]  }|t        u r|j                  |        t        |      dk(  sJ d       |d   }t        |      }
t        |
t               r#t        |      d   }t        |      rJ d       d}n]t        |
t"              rMg }t        |      D ]0  }t        |      rJ d       |j                  t%        ||             2 t#        |      }d}|t%        ||      }t'        |      }|rt)        ||	      }|rt+        t        |            }t        |t              r|t,        u rd}	d }t/        | j0                        }|	r	d
| d| }nd
| }| j0                  g}|j2                  r|j5                  |j2                         n|j                  |       t7        d)i d|d|j8                  d|j:                  d|j<                  d|j>                  d|j@                  d|	d|d|jB                  d|jD                  d|d|jF                  d|jH                  d|jJ                  d|jL                  d|d|dtO        |jP                  |      d|jR                  d |jT                  d!|jV                  d"|jX                  d#|jZ                  d$t]        |j^                        d%|j`                  |fS t        |t
              r| j0                  g}d }|rd&}tc        d)i d|d|d|d'|d|j8                  d|jJ                  d|jL                  d|jF                  d|jH                  d|dtO        |jP                  |      d|jR                  d |jT                  d!|jV                  d"|jX                  d#|jZ                  d$t]        |j^                        d%|j`                  |fS te        d(      )*NFTr   z+Typer Currently doesn't support Union typesr   z=List types with complex sub-types are not currently supportedz>Tuple types with complex sub-types are not currently supported)r   r  )r   r  z--z/--no-param_declsshow_defaultpromptconfirmation_promptprompt_required
hide_inputis_flagmultiplecountallow_from_autoenvr   r   r   show_choicesshow_envvarrequiredr  r   r   r   metavarexpose_valueis_eagerenvvarshell_completeautocompletionr   nargsz$A click.Parameter should be returnedr   )3r   r  r.   r0   emptyr"   r-   r   r   r   r   r   r,   r^   r   r   r  r  rE  r   r  r  r   r   rI   rI  extendr    rJ  rK  rL  rM  rN  rQ  rR  r   r   rS  rT  get_param_callbackr   rW  rX  rY  rZ  r[  get_param_completionr\  r   r   AssertionError)r   r  rU  r  r   	main_typeis_listis_tupleparameter_typerO  originr	  r   r   default_option_namedefault_option_declarationrI  r^  s                     rE   ro   ro   ]  s    MH%--/!!X-H*22M	(	"emmu{{&B%#u{{*%%

IGHNG	"FFE!), $H$U#$ u:?Q$QQ?aI	*Ffd+ +A.I!), O, G.E!), %e, T, "eNS	 #5\NH' 
 )3I+}
	 ,Xi-@A	.*-G "N.uzz:()0C/DE ' ,..A-B)C&zzl%%~99:9: ' ,88 &,,	
 %3$F$F !/ > > *44   ! %** $2#D#D $ $(( &,, ,88  +66!$ "%& &'( ,+44	). '../0 ,8812 (0034 &,,56  .<<78  4N4Q4QR9< !/ > >=@ C"
 "	
F 
NL	1zzlE ' $ "	
  ,88 ,88 +66 $(( &,, & ,+44	" '..#$ ,88%& (00'( &,,)*  .<<+,  4N4Q4QR-0 !/ > >14 7
 	
: ?
@@rm   rV  c                 T   	  sy t               }d d d 	g }|j                         D ]d  \  }}t        |j                  t        j
                        r|-t        |j                  t        j                        r|T|j                  |       f |r|j                         	|r?|j                  d      |r|j                  d      |rt	        j                  d      dt        j
                  dt        j                  dt        dt        f 	fd}t        |        |S )Nr   z3Too many CLI parameter callback function parametersctxr   r   r8   c                 \    i }r| |<   r||<   	rr	 |      }n|}||	<    di |S r  r   )
rl  r   r   r  	use_valuer   click_param_namer   ctx_name
value_names
        rE   r  z#get_param_callback.<locals>.wrapper"  sP    %'
#&Jx +0J'(%e,	!	%.Jz"%*%%rm   )r3   r   r   r   rT   r   	Parameterr^   popClickExceptionr   r   )
r   r   r   untyped_namesr   	param_sigr  ro  rp  rq  s
   ``     @@@rE   ra  ra     s&   
 )(3JHJ!M!+!1!1!3 -
Ii22EMMB!H	 4 4eooF)  ,- "&&(
$((+H##0#4#4Q#7 &&E &U]] &5?? &3 &3 & & 7H%Nrm   c                 @   	
  sy t               }d 	d d 
t        |j                               }|d d  D ]  }t        |j                        }t        |j                  t        j                        r|j                  	|j                  |       Zt        |t              r|j                  |j                  |       t        |j                  t              s|j                  
|j                  |        |d d  D ]  }	-|j                  dk(  r|j                  	|j                  |       2-|j                  dk(  r|j                  |j                  |       a
d|j                  dk(  st|j                  
|j                  |        |rAdj                  |D cg c]  }|j                   c}      }t        j                  d|       dt        j                  dt        t           dt        t           dt        f 	
fd}t        |        |S c c}w )Nrl  r   
incomplete z,Invalid autocompletion callback parameters: r8   c                 B    i }r| |<   r||<   r||<    di |S r  r   )rl  r   rx  r  	args_namer   rp  incomplete_names       rE   r  z%get_param_completion.<locals>.wrapper[  s=    %'
#&Jx $(Jy!*4J'%*%%rm   )r3   r  r   r   r   r   rT   r   rI   remover   joinrt  r   r   r   )r   r   unassigned_paramsrv  rh  r   show_paramsr  r{  rp  r|  s   `       @@@rE   rb  rb  4  s    )(3JHIOZ..01&q) 
0	I001i22EMMB ~~H$$Y/-!I$$Y/	 4 4c:'nnO$$Y/
0 'q) 	0		% 7 ~~H$$Y/9>>V#;!I$$Y/$<)G'nnO$$Y/	0 hh8IJu

JK"":;-H
 	
&U]] &$s) &# &SV & & 7H%N!  Ks   "HfunctionzN
            The function that should power this CLI application.
            c                 V    t        d      } |j                         |         |        y)a  
    This function converts a given function to a CLI application with `Typer()` and executes it.

    ## Example

    ```python
    import typer

    def main(name: str):
        print(f"Hello {name}")

    if __name__ == "__main__":
        typer.run(main)
    ```
    F)r   N)rw   r   )r  apps     rE   runr  i  s#    2 u
%CCKKM(Erm   c                  0    t        j                         dk(  S )NDarwinplatformsystemr   rm   rE   	_is_macosr    s    ??((rm   c                  ^    t        j                         dk(  rydt        j                         v S )NLinuxTBSDr  r   rm   rE   _is_linux_or_bsdr    s&    G#HOO%%%rm   urlzA
            URL or filename of the thing to launch.
            waitz
            Wait for the program to exit before returning. This only works if the launched program blocks.
            In particular, `xdg-open` on Linux does not block.
            locatea  
            If this is set to `True`, then instead of launching the application associated with the URL, it will attempt to
            launch a file manager with the file located. This might have weird effects if the URL does not point to the filesystem.
            c                 
   | j                  d      s| j                  d      rt               rDt        j                  d| gt        j                  t        j
                        j                         S t               xr t        j                  d      du}|rDt        j                  d| gt        j                  t        j
                        j                         S ddl
}|j                  |        yt        j                  |       S )a  
    This function launches the given URL (or filename) in the default
    viewer application for this file type.  If this is an executable, it
    might launch the executable in a new session.  The return value is
    the exit code of the launched application.  Usually, `0` indicates
    success.

    This function handles url in different operating systems separately:
     - On macOS (Darwin), it uses the `open` command.
     - On Linux and BSD, it uses `xdg-open` if available.
     - On Windows (and other OSes), it uses the standard webbrowser module.

    The function avoids, when possible, using the webbrowser module on Linux and macOS
    to prevent spammy terminal messages from some browsers (e.g., Chrome).

    ## Examples
    ```python
        import typer

        typer.launch("https://typer.tiangolo.com/")
    ```

    ```python
        import typer

        typer.launch("/my/downloaded/file", locate=True)
    ```
    zhttp://zhttps://open)stdoutr=   zxdg-openNr   )rA   r  
subprocessPopenDEVNULLSTDOUTr  r  shutilwhich
webbrowserr  rT   launch)r  r  r  has_xdg_openr  s        rE   r  r    s    r ~~i CNN:$>;##j&8&8ARARdf ()Rfll:.Fd.R##S!**<*<ZEVEVdf 	 ||C  rm   r?   )FF)pr   rN   r  r  r  ra   rX   collections.abcr   r   r   r   	functoolsr   pathlibr   r   r	   r	  r
   typingr   r   r   r   r   uuidr   rT   annotated_docr   typer._typesr   _typingr   r   r   r   r   
completionr   corer   r   r   r   r   r   r    modelsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   utilsr3   r   rQ   rM   r   BaseExceptionrl   r  rr  ru   rw   r   Commandr   r   r   r   r   r   r   r  ArgumentOptionr   r   r   r   r   r   r  r  r   	ParamTyperE  r   ro   ra  rb  r  r  r  r8  r  r   rm   rE   <module>r     s    	    
  $   $  0  < <    $ T T 9      ( , 'F $0=!0.;0AI-AX0	0f1%0P*Q 1Q Qh e 
 # #%-- #L"!i "!C "!J )  	  FKK "K 	K
 !K K\*3 *3 *2xS)*2
4ennell234d38nhsmST2&** "* !	*
 ]]*ZC HXseSj5I,J  $ 
$t* 
3%*1E 
#,->Fsmx&'$s))<<=C=xc3h()8E#s(O+DDE( .2(*<@(,xS)* U__% c8SE3J#7789	
 ! " hsCx !Dd@d@(5d@
__d@NE	E#GU7C<-@$@AE	E`A`A
5-.34`AJ .2.21xS)*1 c*+1 hsCx !	1j .22xS)*2hsCx !2j
c	
	
 

<)4 )&$ &0 	 	5M!		
	
M! 	
	M!$ 	
	%M!6 	7M!rm   