
    k7iu                    ,   S SK r S SKrS SKrS SKrS SKrS SKJrJrJrJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJrJr  S SKJr  S SKJr  S S	KJr  S S
KJrJrJrJrJrJrJ r J!r!J"r"  S SK#J$r$J%r%J&r&  S SK'J(r(  S SK)J*r*  S SK+J,r,  S SK-J.r.J/r/J0r0  S SK1J2r2  S SK3J4r4  S SK5J6r6J7r7J8r8J9r9J:r:J;r;  S SK<J=r=J>r>  S SK?J@r@  S SKAJBrB  S SKCJDrDJErE  S SKFJGrG  S SKHJIrI  S SKJJKrKJLrLJMrMJNrNJOrOJPrPJQrQJRrR  \R                  S:  a  O \" \T5         S SKUrUSSS5        \(       a  S SKVJWrW  S SKXJYrY  S SKZJ[r[  S SK\J]r]  S SK^J_r_J`r`  S S KaJbrb  \" S!\S"\4   S#9rc\" S$5      rdS%reS&S\-  \\   -  S'\f\S"4   S-  4S( jrg " S) S*\h5      riS+ rjS, rkS- rlSBS1 jrmS2\n\o\4   S0S/S'S4S3 jrpS4\oS'\o4S5 jrq SCS.\S/   S'\n\oS64   4S7 jjrrSDS8 jrsS9S\o-  \=-  S'\=S-  4S: jrt\% " S; S/5      5       ruS'\vS-  4S< jrw " S= S>\o\5      rx\S'\x4S? j5       ry\S@\xS'S4SA j5       rzg! , (       d  f       GN	= f)E    N)Callable	CoroutineIterableIteratorSequence)suppress)copy)Enum)	lru_cachepartial)chain)Path)
ModuleType)	TYPE_CHECKING	AnnotatedAnyLiteralOptionalTypeVarUnioncastoverload)Factorydefinefield)resolve_annotated)AppStack)ArgumentCollection)create_bound_argumentsis_option_likenormalize_tokens)CommandSpec)Env)CommandCollisionErrorCycloptsErrorUnknownCommandErrorUnknownOptionErrorUnusedCliTokensErrorValidationError)Groupsort_groups)groups_from_app)CycloptsPanel)	Parametervalidate_command)
Dispatcher)Token)UNSET!create_error_console_from_consoledefault_name_transformhelp_formatter_converteroptional_to_tuple_convertersort_key_converterto_list_converterto_tuple_converter)      Console)	DocFormat)	HelpPanel)HelpFormatter)ResultActionResultActionSingle)_run_maybe_async_commandT.)boundVmarkdownvaluereturnc                 H    U c  g[        U 5      nU(       d  [        S5      eU$ )zConvert result_action value, ensuring non-empty sequences.

Intended to be used in an ``attrs.Field`` for result_action.
Raises ValueError if an empty iterable is provided.
Nz)result_action cannot be an empty sequence)r9   
ValueError)rH   results     G/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/core.py_result_action_converterrN   U   s*     }&FDEEM    c                       \ rS rSrSrg)#_CannotDeriveCallingModuleNameErrorf    N)__name__
__module____qualname____firstlineno____static_attributes__rS   rO   rM   rQ   rQ   f   s    rO   rQ   c                      [         R                  " 5        HP  n [         R                  " U R                  5      nUc  M(  UR                  R                  S5      S   nUS:X  a  MN  Us  $    [        e)z1Get the calling package name from the call-stack..r   cyclopts)inspectstack	getmoduleframerT   splitrQ   )elemmoduleroot_module_names      rM   _get_root_module_namerd   j   sa    ""4::.>!??005a8z)   .-rO   c                 F    [        U [        5      (       a  [        S5      eU $ )N%Cannot register a sub-App to default.)
isinstanceApp	TypeError)xs    rM   _validate_default_commandrk   x   s     !S?@@HrO   c                     [        U R                  5      (       a1  [        R                  " U R                  5      (       a  U R                  $ U R
                  $ N)callableversionr\   iscoroutinefunction_version_print_asyncversion_print)apps    rM   _get_version_commandrt   ~   s=    !<!<S[[!I!I'''   rO   rs   rh   
parent_appc                 H   U R                   c  [        UR                   5      U l         U R                  c  [        UR                  5      U l        U R                  c  [        UR                  5      U l        U R                  c   UR                  b  UR                  U l        ggg)zApply parent app's group defaults to app if not already set.

Parameters
----------
app : App
    The app to apply defaults to.
parent_app : App
    The parent app to inherit defaults from.
N)_group_commandsr	   _group_parameters_group_argumentsro   )rs   ru   s     rM   _apply_parent_defaults_to_apprz      s     "":#=#=>
$ $Z%A%A B
##J$?$?@
{{z11= ((  >rO   kwargsc                     SU ;  a  [        UR                  5      U S'   SU ;  a  [        UR                  5      U S'   SU ;  a  [        UR                  5      U S'   gg)zApply parent app's groups to kwargs dict if not already specified.

Parameters
----------
kwargs : dict
    Keyword arguments dict to modify.
parent_app : App
    The parent app to inherit groups from.
group_commandsgroup_parametersgroup_argumentsN)r	   rw   rx   ry   )r{   ru   s     rM   _apply_parent_groups_to_kwargsr      sc     v%#'
(B(B#C '%)**F*F%G!"&$()D)D$E ! 'rO   sc                 b    U R                  SS5      R                  SS5      R                  5       $ )a-  Normalize a string for fuzzy command matching.

Removes hyphens, underscores, and converts to lowercase (e.g.,
'mycommand' matches 'my-command').

.. warning::
    This fuzzy matching is primarily for backward compatibility with the
    introduction of ``_pascal_to_snake`` in ``default_name_transform``.
    It should **probably be removed in v5** once users have migrated their
    camelCase command names.

Parameters
----------
s : str
    String to normalize.

Returns
-------
str
    Normalized string with hyphens/underscores removed and lowercased.
- _)replacelower)r   s    rM   _normalize_for_matchingr      s+    , 99S"%%c2.4466rO   App | CommandSpecc                 |   U c  0 $ [        U R                  5      nU R                   H  nU H  nXS;  d  M
  XE   X5'   M     M     U(       a4  U R                  (       a#  UR	                  [        U R                  SS95        U(       a6  U R                  (       a%  [        U R                  SS9nUR	                  U5        U$ )a*  Return a mapping of command names to Apps or CommandSpecs.

CommandSpec instances are NOT resolved here - they are resolved lazily
only when the command is actually executed, enabling true lazy loading.

Parameters
----------
app : App | None
    The app to get commands from.
recurse_meta : bool
    If True, include commands from the app's meta.
recurse_parent_meta : bool
    If True, include commands from parent meta apps.

Returns
-------
dict[str, App | CommandSpec]
    Mapping of command names to :class:`App` or :class:`CommandSpec` instances.
Frecurse_parent_metarecurse_meta)dict	_commands_flattened_subapps_metaupdate_combined_meta_command_mapping_meta_parent)rs   r   r   command_mappingsubappcmd_namemeta_parent_commandss          rM   r   r      s    , {	3==)O ((H.,2,<)  )
 		=cii]bcds//=c>N>N]bc34rO   c              #      #    U /nU nUR                   =n(       aH  UR                  (       a7  UR                  U5        UR                   =n(       a  UR                  (       a  M7  [        U5       Sh  vN   g N7f)zsTypically the result looks like [app] or [meta_app, app].

Iterates from deepest to shallowest meta-app (and app).
N)r   default_commandappendreversed)rs   	meta_listmetas      rM   _walk_metasr      sb     
 ID::44#7#7 ::44#7#7#7	"""s   AA9#A91A72A9input_valuec                     U c  g [        U [        5      (       a  [        U 5      $ [        U [        5      (       a  U $ [        erm   )rg   strr*   ri   )r   s    rM   _group_converterr      s;    	K	%	%[!!	K	'	'rO   c                   8   \ rS rSr% \" SS\S9rS\-  \\S4   -  \	S'   \" SSS9r
\S-  \	S	'   \" SS
9r\S-  \	S'   \" S\SS9rS\-  \\S4   -  \	S'   \" S\SS9r\S\4   S-  \	S'   \" SSS9r\S-  \	S'   \" SS\SS9rS\\S    \\S4   \/\4   -  \\\S    \\S4   \/\4      -  \	S'   \" SSS9rS\-  \S\4   -  \S\\\\4   4   -  \	S'   \" S/\SSS9r\\\   -  \	S'   \" SSS9r\\	S'   \" SSSS9r\S   \	S'   \" SSSS9r\S   \	S '   \" S!S"/\S#SS9r \\\   -  \	S$'   \" SSS9r!\"S%   S-  \	S&'   \" SSS9r#\S-  \	S''   \" SSS9r$\S-  \	S('   \" SSS9r%\"S%   S-  \	S)'   \" S\SS9r&\'\-  \\'\-  S4   -  \	S*'   \" S+S\(SS,9r)\'\-  S-  \	S-'   \" S.S\(SS,9r*\'\-  S-  \	S/'   \" S0S\(SS,9r+\'\-  S-  \	S1'   \" S\,SS9r-\\S\4      \	S2'   \" SS3SS49r.\\/\4   S-  \	S5'   \" SS6\/SS9r0\\	S7'   \" SSS9r1\S-  \	S8'   \" SSS9r2\S-  \	S9'   \" SSS9r3\S-  \	S:'   \" SSS9r4\S-  \	S;'   \" SSS9r5\\	S<'   \" SSS9r6\"S=   S-  \	S>'   \" S\7SS9r8\9S\"S?   S@4   \	SA'   \" S\:SS9r;\<\=-  S-  \	SB'   \" SC\>SD9r?\>\SE4   \	SF'   \" SC\SD9r@\S    \	SG'   \" SCSSH9rA\S    \	SI'   \" SCSSH9rB\S    \	SJ'   \" SCSSCSK9rC\S-  \	SL'    \" SC\DSCSK9rE\FS-  \G\D   -  \	SM'    \" SCSSH9rH\S   \	SN'   \" SCSSH9rI\S   \	SO'   \" SC\J" \KSSP9SH9rL\K\	SQ'   SR rMSS\\   4ST jrN\OSU 5       rP\PR                  SV 5       rP\OSW 5       rR\RR                  SX 5       rR\OSY\\S4   4SZ j5       rS\OS[ 5       rT\TR                  S\ 5       rT\OS] 5       rU\UR                  S^ 5       rU\OS_ 5       rV\VR                  S` 5       rV\OSa 5       rW\WR                  Sb 5       rW\OSY\4Sc j5       rX\XR                  Sd 5       rX\OSe 5       rY\YR                  Sf 5       rY\OSg 5       rZ\ZR                  Sh 5       rZ\OSY\>\S 4   4Si j5       r[\OSSj j5       r\\\R                  S\S   4Sk j5       r\\OSSl j5       r]\]R                  S\S   4Sm j5       r]\OSY\FS-  4Sn j5       r^SSo\SY\4Sp jjr_Sq\S\S   SYS4Sr jr` SS\a\S   \" SCSs94   SYS4St jjrb SS\a\S   \" SCSs94   SYS4Su jjrc\OSv 5       rdSY\>\S 4   4Sw jreSx\SYS 4Sy jrfSSSz jjrgSx\4S{ jrhS|\SY\4S} jriSY\j\   4S~ jrk\OSS j5       rl SSS.SS\-  \\   -  SY\\\S4   \S   \\   4   4S jjjrmS\nS    SY\S    4S jroS\S    S\\   SY\\   4S jrp\q SSS.S\rSS\-  \\   -  SS\-  \\   -  S\sSY\r4
S jjj5       rt\q  SSS.SSSS\-  \\   -  SS\-  \\   -  S\sSY\\r/\r4   4
S jjj5       rt\q SSS.S\SS\-  \\   -  SS\-  \\   -  S\sSYS4
S jjj5       rt  SSS.S\rS-  \-  SS\-  \\   -  SS\-  \\   -  S\sSY\r\\r/\r4   -  S-  4
S jjjrt\qSS.S\rS2\S\4   S-  SY\r4S jj5       ru\q SSS.SSS2\S\4   S-  SY\\r/\r4   4S jjj5       ru SSS.S\rS-  S2\S\4   S-  SY\r\\r/\r4   -  4S jjjruSSCS.S\S-  S\SY\4S jjrv SSSSS.SS\-  \\   -  S\S   S\S   S8\S-  SY\\S\4   \wR                  \\   \>\\4   4   4
S jjjry SSCS.SS\-  \\   -  S\SY\\S\4   \wR                  \\   \>\\4   \4   4S jjjrz SSSSSSSSS.SS\-  \\   -  S\S   S\S   S9\S-  S:\S-  S'\S-  S;\S-  S8\S-  SY\\\wR                  \>\\4   4   4S jjjr{SY\4S jr| SSSSSSSSSSS.	SS\-  \\   -  S\S   S\S   S9\S-  S:\S-  S'\S-  S;\S-  S8\S-  S>\"S=   S-  SB\<S-  SY\4S jjjr} SSSSSSSSSSS.	SS\-  \\   -  S\S   S\S   S9\S-  S:\S-  S'\S-  S;\S-  S8\S-  S>\"S=   S-  SB\<S-  SY\4S jjjr~ SSS.S\aS\-  \\   -  \" SCS94   S\a\S   \" SCSs94   SYS4S jjjrSS\-  \\   -  SY\\\S   S4      4S jr     SSSS\S\S\S\SY\4S jjrSSS.S\S-  S\"S   S-  SY\4S jjrSSSS.S\"S   S-  S\S-  S\SY\4S jjr  SS\\\   -  S\SYS4S jjr      SS\SS\-  \\   -  S\S-  SSS:\SB\<S-  SYS4S jjrSS\S\<SY\4S jjrSS jrS rSrg)rh   i  Nname)defaultalias	converter._namehelp)r   r   _help)r   usageT)r   r   kw_onlyr   r   )r   r   default_parameterconfig)r   r   r   r   _configro   z	--versionversion_flags)r   r   r   r   _version_flagsshowconsole)r   r   r   r=   _consoleerror_console_error_consolez--helpz-h
help_flags_help_flags)rG   md	plaintextrestructuredtextrstrichhelp_formathelp_on_errorhelp_epilogueversion_formatgroupr   )r   r   r   r   ry   r~   rx   r}   rw   	validatorname_transform)r   r   r   _name_transformsort_key	_sort_keyend_of_options_delimiterprint_errorexit_on_errorverbosesuppress_keyboard_interruptasynciotriobackend)r   plainr@   help_formatterresult_actionF)initfactoryr   r   r   )r   r   r   r   )r   r   repr_instantiating_module_name_instantiating_module_cache_fallback_console_fallback_error_console)
takes_self	app_stackc                     U R                   U l        U R                  U l         [        R
                  " S5      nUR                  R                  S5      U l        g ! [        [        4 a
    S U l         g f = f)N   rT   )r   r   r   r   sys	_getframe	f_globalsgetr   
IndexErrorAttributeError)selfr_   s     rM   __attrs_post_init__App.__attrs_post_init__  sc    **!00	3MM!$E.3oo.A.A*.MD+N+ 	3.2D+	3s   6A A54A5commandsc                 >    U H  n X	 M     g! [          a     M  f = f)zSafely delete commands.

Will **not** raise an exception if command(s) do not exist.

Parameters
----------
commands: Iterable[str, ...]
    Strings of commands to delete.
N)KeyError)r   r   commands      rM   _delete_commandsApp._delete_commands  s,      GM    s   
c                     U R                   $ rm   )r   r   s    rM   r   App.version_flags  s    """rO   c           	          U R                  U R                  5        Xl        U R                  (       a3  U R                  U R                  U R                  / / U R                  SS9  g g )NzDisplay application version.r   r   r   ro   r   )r   r   r   rr   ro   r   rH   s     rM   r   r     s]    d112#LL""(( 3   rO   c                     U R                   $ rm   )r   r   s    rM   r   App.help_flags  s    rO   c           	          U R                  U R                  5        Xl        U R                  (       a3  U R                  U R                  U R                  / / U R                  SS9  g g )NzDisplay this message and exit.r   )r   r   r   
help_printro   r   s     rM   r   r     s[    d../ LL%% 5   rO   rI   c                    U R                   (       a  U R                   U R                  -   $ U R                  cF  [        [        R
                  S   5      R                  nUS:X  a
  [        5       nU4U R                  -   $  U R                  R                  nU R                  U5      4U R                  -   $ ! [         a#    U R                  R                  R                  n NKf = f)z?Application name(s). Dynamically derived if not previously set.r   z__main__.py)r   r   r   r   r   argvr   rd   rT   r   funcr   )r   r   	func_names      rM   r   App.name  s     ::::

**!!)$))D}$,.7TZZ''? 0099	 ''	24tzzAA " ? 0055>>	?s   ?B4 4*C! C!c                 ^    U R                   c  [        R                  " 5       $ U R                   $ rm   )ry   r*   create_default_argumentsr   s    rM   r   App.group_arguments  s)      (1133$$$rO   c                     Xl         g rm   )ry   r   s     rM   r   r    s     %rO   c                 ^    U R                   c  [        R                  " 5       $ U R                   $ rm   )rx   r*   create_default_parametersr   s    rM   r~   App.group_parameters  s)    !!)2244%%%rO   c                     Xl         g rm   )rx   r   s     rM   r~   r    s    !&rO   c                 ^    U R                   c  [        R                  " 5       $ U R                   $ rm   )rw   r*   create_default_commandsr   s    rM   r}   App.group_commands  s)    '0022###rO   c                     Xl         g rm   )rw   r   s     rM   r}   r	  %      $rO   c                 8    U R                   R                  S5      $ )Nr   )r   resolver   s    rM   r   
App.config)  s    ~~%%i00rO   c                     Xl         g rm   )r   r   s     rM   r   r  -  s    rO   c                    U R                   b  U R                   $ U R                  c$  U R                  c  gU R                  R                  $ S[
        R                  ;   aY  SSKJn  [        U R                  U5      (       a!  U R                  R                  R                  nO-U R                  R                  nOU R                  R                  nUc  gU$ )Nr   	functoolsr   r   )r   r   r   r   r   r   modulesr  r   rg   r   __doc__)r   r   docs      rM   r   App.help1  s    ::!::!!)zz!yy~~% ckk)-d22G<<..33;;C..66C**22{
rO   c                     Xl         g rm   )r   r   s     rM   r   r  L  s    
rO   c                 H    U R                   (       a  U R                   $ [        $ rm   )r   r4   r   s    rM   r   App.name_transformP  s    '+';';t##WAWWrO   c                     Xl         g rm   )r   r   s     rM   r   r  T  r  rO   c                 D    U R                   [        L a  S $ U R                   $ rm   )r   r2   r   s    rM   r   App.sort_keyX  s    ~~.tBDNNBrO   c                 $    [        U5      U l        g rm   )r7   r   r   s     rM   r   r  \  s    +E2rO   c                 h    0 nU  H)  nX R                   ;   d  X R                  ;   a  M#  X   X'   M+     U$ )z`Commands that are not help or version commands.

This includes commands from flattened subapps.
)r   r   )r   outrj   s      rM   _registered_commandsApp._registered_commands`  s;     AOO#q,>,>'>WCF  
rO   c                     U R                   R                  S5      nUb  U$ U R                  c  SSKJn  U" 5       U l        U R                  $ )Nr   r   r<   )r   r  r   rich.consoler=   )r   rL   r=   s      rM   r   App.consolem  sH    ''
3M
 !!),%,YD"%%%rO   c                     Xl         g rm   )r   r   r   s     rM   r   r$  }  s    rO   c                     U R                   R                  S5      nUb  U$ U R                  c  [        U R                  5      U l        U R                  $ )Nr   )r   r  r   r3   r   )r   rL   s     rM   r   App.error_console  sK    ''(89M''/+LT\\+ZD(+++rO   c                     Xl         g rm   )r   r&  s     rM   r   r(    s    %rO   c                     U R                   [        L aG  U R                  (       a/  [        R                  R                  U R                  5      U l         OSU l         [        [        S-  U R                   5      $ )z2Lazily resolve the module name to a module object.N)r   r2   r   r   r  r   r   r   r   s    rM   _instantiating_moduleApp._instantiating_module  sV     ++u4..36;;??4CbCb3c0370J%t'G'GHHrO   r   c                    SSK Jn  SSK Jn  U R                  b3  U R                  R                  nUR                  S5      S   n U" U5      $  [        5       n U" U5      $ ! U a     Of = f U R                  R                  $ ! [         a     NCf = f! [         a    Us $ f = f! U a     Of = f [        R                  " U5      nUR                  $ ! [        [        4 a     U$ f = f)aT  Get the version string with multiple fallback strategies.

First tries to derive from the instantiating module, then tries to get it
from the calling code's module, and finally falls back to a default.

Parameters
----------
default : str
    Default version to use if no version can be determined.

Returns
-------
str
    Version string.
r   )PackageNotFoundError)ro   rZ   )importlib.metadatar.  ro   r+  rT   r`   __version__r   rd   rQ   	importlibimport_moduleImportError)r   r   r.  importlib_metadata_versionfull_module_namerc   rb   s          rM   _get_fallback_version_string App._get_fallback_version_string  s     	<L%%1#99BB/55c:1=12BCC	46	-.>?? ( 11===! 
 3 	N	
 $ 			,,-=>F%%%^, 		sZ   A! 
B B& !A*)A*.B 
BBB#"B#&B/.B/3!C C)(C)version_rawc                     SSK Jn  U R                  R                  S5      nUc  U R                  R                  S[        S9nUR                  XS9nU=(       d    U R                  R                  U5        g)zFormat and print the version string.

Parameters
----------
version_raw : str
    Raw version string to format and print.
console : ~rich.console.Console
    Console to print to.
r   
InlineTextr   Nr   fallbackformat)cyclopts.helpr;  r   r  _DEFAULT_FORMATfrom_formatr   print)r   r8  r   r;  r   version_formatteds         rM   _format_and_print_versionApp._format_and_print_version  sg     	-//0@A!!^^33MO3\N&22;2V		 DLL''(9:rO   parsec                 L   U R                   bv  [        U R                   5      (       aO  [        R                  " U R                   5      (       a  [	        S5      e[        [        U R                  5       5      nOU R                   nOU R                  5       nU R                  X!5        g)zPrint the application version.

Parameters
----------
console: ~rich.console.Console
    Console to print version string to.
    If not provided, follows the resolution order defined in :attr:`App.console`.

NzJasync version handler detected. Use App.run_async within an async context.)	ro   rn   r\   rp   rK   r   r   r6  rE  r   r   r8  s      rM   rr   App.version_print  su     <<#%%..t||<<$%qrr"37"ll;;=K&&{<rO   c                 t  #    U R                   b  [        U R                   5      (       a]  [        R                  " U R                   5      (       a  U R                  5       I Sh  vN nO<[	        [
        U R                  5       5      nOU R                   nOU R                  5       nU R                  X!5        g NS7f)zAsync version of version_print for handling async version callables.

Parameters
----------
console: ~rich.console.Console
    Console to print version string to.
    If not provided, follows the resolution order defined in :attr:`App.console`.

N)ro   rn   r\   rp   r   r   r6  rE  rJ  s      rM   rq   App._version_print_async  s      <<#%%..t||<<(,"6K
 #'sDLLN";K"ll;;=K&&{< #7s   A B8"B6#AB8c              #   *   #    U  H	  nX   v   M     g 7frm   rS   )r   ks     rM   subappsApp.subapps  s     A'M s   c           	         U R                   R                  5        VVs0 s H.  u  pU[        U[        5      (       a  UR	                  U 5      OU_M0     nnnU R
                   H  nU H  nXS;  d  M
  XE   X5'   M     M     U$ s  snnf )a  Get all commands as resolved App instances.

This function resolves any lazy-loaded commands (CommandSpec) into App instances.
Note: This will import modules for all lazy-loaded commands, which may impact performance
and memory usage. Consider accessing commands individually via ``app["command_name"]`` if
you don't need all commands at once.

Returns
-------
dict[str, App]
    Mapping of command names to resolved :class:`App` instances.

Examples
--------
.. code-block:: python

    from cyclopts import App

    app = App()
    app.command("myapp.commands:create")
    app.command("myapp.commands:delete")

    # Resolve all lazy commands
    commands = app.resolved_commands()
    assert "create" in commands
    assert isinstance(commands["create"], App)
)r   itemsrg   r"   r  r   )r   r   cmdresolvedr   r   s         rM   resolved_commandsApp.resolved_commands  s    : _c^l^l^r^r^t
^tQZQUDz#{'C'C#++d#L^t 	 

 --F"+)/)9H& # .
 
s   5Bkeyc                 t    U R                  U5      n[        U[        5      (       a  UR                  U 5      $ U$ )a  Get the subapp from a command string.

All commands get registered to Cyclopts as subapps.
The actual function handler is at ``app[key].default_command``.

If the command was registered via lazy loading (import path string),
it will be imported and resolved on first access.

Example usage:

.. code-block:: python

    from cyclopts import App

    app = App()
    app.command(App(name="foo"))


    @app["foo"].command
    def bar():
        print("Running bar.")


    app()
)	_get_itemrg   r"   r  )r   rX  rT  s      rM   __getitem__App.__getitem__E  s3    4 nnS!c;'';;t$$
rO   c                 R   U(       aD  U R                   (       a3  [        [        5         U R                  R	                  USS9sSSS5        $ U R
                  (       a3  [        [        5         U R
                  R	                  USS9sSSS5        $ XR                  ;   a  U R                  U   $ U R                   H,  n[        [        5         UR	                  USS9sSSS5        s  $    [        U5      e! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       Ml  = f)z;Internal getter that returns App or unresolved CommandSpec.Tr   NF)r   r   r   r   rZ  r   r   r   )r   rX  r   r   s       rM   rZ  App._get_iteme  s    DJJ(#yy**3T*B $#(#((223U2K $# .. >>#&& --F(#''%'@ $# . sm $# $# $#s#   C5,DD5
D
D
D&	c                     U R                   U	 g rm   )r   )r   rX  s     rM   __delitem__App.__delitem__y  s    NN3rO   rO  c                     XR                   ;   a  gU R                  (       a  XR                  ;   a  gU R                   H
  nX;   d  M
    g   g)NTF)r   r   r   )r   rO  r   s      rM   __contains__App.__contains__|  sD    %%%--F{ . rO   c              #   T  #    [        U R                  5      nU Sh  vN   [        U5      nU R                  (       a/  U R                   H  nX!;  d  M
  Uv   UR	                  U5        M!     U R
                   H(  nU H  nX!;  d  M
  Uv   UR	                  U5        M!     M*     g N7f)a\  Iterate over command & meta command names.

Example usage:

.. code-block:: python

    from cyclopts import App

    app = App()


    @app.command
    def foo():
        pass


    @app.command
    def bar():
        pass


    # help and version flags are treated as commands.
    assert list(app) == ["--help", "-h", "--version", "foo", "bar"]
N)listr   setr   addr   )r   r   r   r   s       rM   __iter__App.__iter__  s     2 'x=,,*!MLL) -
 --F!*!MLL) " . 	s   B(B&2B(0B(B(c           	      4   U R                   c  [        U 5      " U R                  U R                  [	        U R
                  5      [	        U R                  5      [	        U R                  5      U R                  S9U l         X R                   l	        U R                   $ )N)r   r   r}   r   r~   r   )
r   typer   r   r	   rw   ry   rx   r   r   r   s    rM   r   App.meta  su    ::d??"00#D$8$89 $T%:%: ;!%d&<&<!="00DJ '+JJ#zzrO   include_parent_metatokens)rh   .c          
      d  ^^ [        U5      n/ nU n/ mUnUU4S jnU" U5        TR                  U5        [        UTS9nUnU(       GaL  US   nSn	X;   a  Xx   n	OUR                  S5      (       d~  [	        U5      n
U Vs/ s H  n[	        U5      U
:X  d  M  UPM     nn[        U5      S:X  a  X|S      n	O9[        U5      S:  a*  [        SU SS	R                  [        U5      5       S
35      eU	c6  T(       a.  U R                  TU5      n[        U5      [        U5      :  a  UnM  On[        U	[        5      (       a  UnU	R                  U5      nOU	nU" U5        TR                  U5        [        UTS9nUR                  U5        USS nU(       a  GML  [        U5      [        T5      U4$ s  snf )a  Extract out the command tokens from a command.

You are probably actually looking for :meth:`parse_args`.

Parameters
----------
tokens: None | str | Iterable[str]
    Either a string, or a list of strings to launch a command.
    Defaults to ``sys.argv[1:]``
include_parent_meta: bool
    Controls whether parent meta apps are included in the execution path.

    When True (default):
    - Parent meta apps (i.e. the "normal" app ) are added to the apps list.
    - Meta app options are consumed while parsing commands.
    - Used for getting the inheritance hierarchy.

    When False:
    - Meta app options are treated as regular arguments.
    - Used for getting the execution hierarchy.

    This parameter is primarily for internal use.

Returns
-------
tuple[str, ...]
    Strings that are interpreted as a valid command chain.
tuple[App, ...]
    The execution path - apps that will be invoked in order.
list[str]
    The remaining non-command tokens.
c                    > T(       d  g/ nU nUR                   =nb"  UR                  U5        UR                   =nb  M"  TR                  USSS2   5        g)ztIf ``app`` is a meta-app, also add it's "normal" app.

We assume that ``app._meta`` will always invoke the ``app``.
N)r   r   extend)rs   meta_parentsmeta_parentappsro  s      rM   add_parent_metas,App.parse_commands.<locals>.add_parent_metas  s^    
 'LK"-":"::;G##K0 #.":"::;G KKTrT*+rO   r   r   Nr      zAmbiguous command 'z'. Could match: , rZ   )r!   r   r   
startswithr   lenrK   joinsorted_consume_leading_meta_optionsrg   r"   r  tuple)r   rp  ro  command_chainrs   unused_tokensrx  r   tokenapp_or_specnormalized_tokenr   matches	remainingru   rw  s     `            @rM   parse_commandsApp.parse_commands  s   L "&)	, 	C8Ref!!$EK '-4 %%c** $;5#A -<-<@WX`@aeu@uH_   w<1$"1!*"=K\A%$':5'AQRVR[R[\bcj\kRlQmmn%opp" ' $ B B4 WI9~M(::(1 
 +{33 
!))*5! S!KK<SVijO  ')!"-Mk mn ]#U4[-??Qs    F-F-execution_pathc                    / nU(       a  US   n[        U5       H  nXB;  d  M
  UR                  U5        M     UR                  R                  (       a  UR                  R                  S    Hr  nUR                  (       d  M  UR                  U;  d  M(  X4R                  R
                  R                  5       ;   nU(       a  MW  UR                  UR                  5        Mt     U$ )at  Get all apps that contribute to parameter resolution for the given execution path.

This includes parent meta apps and the meta app of the final command app.

Parameters
----------
execution_path : Sequence[App]
    The execution path returned from parse_commands.

Returns
-------
list[App]
    All apps that contribute configuration and parameters, ordered by priority.
rs  )r   r   r   r]   r   r   values)r   r  rw  last_apprs   is_meta_commands         rM   _get_resolution_contextApp._get_resolution_context7  s      %b)H"8,?KK$ -
 !!''#--33B7CyyySYYd%:*2ii6I6I6P6P6R*R. KK		2 8 rO   rw  c                 8   U(       a  U(       d  U$ SSK Jn  U R                  U5         U R                  R                  SSS9nSSS5        U Vs/ s H&  oUR                  c  M  UR
                  (       d  M$  UPM(     nnUS   R                  (       a<  US   R                  R
                  (       a  UR                  US   R                  5        UnU H  n UR                  5       n	U" U	UWSS	9nM     U$ ! , (       d  f       N= fs  snf ! [         a     MF  f = f)
a[  Consume meta app options from the beginning of the token stream.

This is used to skip over meta app parameters when looking for commands.

Limitation: positional parameters for the meta app are NOT skipped.
This is because we do not know which meta-parameters are for the
meta-app itself vs which it will pass along to the normal app.

Parameters
----------
apps: list[App]
    Current app stack including parent meta apps.
tokens: list[str]
    Tokens to try parsing, starting from current position.

Returns
-------
list[str]
    The remaining unused tokens after consuming any leading meta options.
r   )_parse_kw_and_flagsr   --r<  Nrs  T)r   stop_at_first_unknown)
cyclopts.bindr  r   r  r   r   r   r   assemble_argument_collection	Exception)
r   rw  rp  r  r   rs   meta_apps_to_tryr  meta_appargument_collections
             rM   r  !App._consume_leading_meta_options\  s   * 6M5 ^^D!'+~~'='=>Xcg'='h$ " ,0h4C3C3CCTWTgTgC4h 8>>d2hnn<<##DHNN3 (H&.&K&K&M# !4'!-E*.	! )  ? "! i(  s/   C5D#D6DD5
D
DD)r   objr{   c                    g rm   rS   r   r  r   r   r{   s        rM   r   App.command  s     rO   c                    g rm   rS   r  s        rM   r   r    s     rO   c                    g rm   rS   r  s        rM   r   r    s     rO   c                6   Uc  [        U R                  4X#S.UD6$ US:X  aZ  [        U[        5      (       d  [	        S5      eU(       a  [        S5      e[        X5        U R                  R                  U5        U$ [        U[        5      (       a  Uc'  UR                  S5      u    pVU R                  U5      4nO[        U5      nUc  SnO[        U5      n[        X(       a  US   OSUS	9nX#-    H%  nX;   a  [        S
U S35      eXpR                  U'   M'     g[        U[        5      (       a;  Un	U	R                   c  Uc  [        S5      eU(       a  [        S5      e[        X5        OUR#                  SU R$                  5        UR#                  SU R&                  5        SU;  a  U R(                  b  U R(                  US'   [+        X@5        [-        U 5      " S0 UD6n	U	R/                  U5        [1        U	R$                  U	R&                  5       H  n
SX   l        M     U	R4                  c  U R                  U	l        Uc  U	R6                  nO[        U5      nUc  SnO[        U5      nX#-    H%  nX;   a  [        S
U S35      eXR                  U'   M'     U$ )a%  Decorator to register a function as a CLI command.

Example usage:

.. code-block::

    from cyclopts import App

    app = App()

    @app.command
    def foo():
        print("foo!")

    @app.command(name="buzz")
    def bar():
        print("bar!")

    # Lazy loading via import path
    app.command("myapp.commands:create_user", name="create")

    app()

.. code-block:: console

    $ my-script foo
    foo!

    $ my-script buzz
    bar!

    $ my-script create
    # Imports and runs myapp.commands:create_user

Parameters
----------
obj: Callable | App | str | None
    Function, :class:`App`, or import path string to be registered as a command.
    For lazy loading, provide a string in format "module.path:function_or_app_name".
name: None | str | Iterable[str]
    Name(s) to register the command to.
    If not provided, defaults to:

    * If registering an :class:`App`, then the app's name.
    * If registering a **function**, then the function's name after applying :attr:`name_transform`.
    * If registering via **import path**, then the attribute name after applying :attr:`name_transform`.

    Special value ``"*"`` flattens all sub-App commands into this app (App instances only).
    See :ref:`Flattening SubCommands` for details.
`**kwargs`
    Any argument that :class:`App` can take.
N)r   r   *zYFlattening (name="*") is only supported for App instances, not functions or import paths.zLCannot supply additional configuration when flattening a sub-App (name="*").:rS   r   )import_pathr   
app_kwargsz	Command "z" already registered.z#Sub-app MUST have a name specified.zDCannot supplied additional configuration when registering a sub-App.r   r   ro   F)r   r   rg   rh   ri   rK   rz   r   r   r   
rpartitionr   r9   r"   r$   r   r   
setdefaultr   r   ro   r   rl  r   r   r   r   r   )r   r  r   r   r{   r   r   specnrs   flags              rM   r   r    sz   x ;4<<JdJ6JJ 3;c3''o   !opp)#4##**3/J c3|"%.."51++I68)$/}*51 3T!W$[abD \9/)A3>S0TUU$(q! "
 c3Cyy T\ !FGG !ghh)#4lDOO<ot/A/AB&4<<+C$(LLy!*68t*&v&CKK#..#*;*;<D"CIN = &!%!4!4C<88D%d+D=E&u-EAy+is:O,PQQ #NN1 
 
rO   r   c                    g rm   rS   r   r  r   s      rM   r   App.default[  s     rO   c                    g rm   rS   r  s      rM   r   r  h  s     rO   c                    Uc  [        U R                  US9$ [        U[        5      (       a  [	        S5      eU R
                  b  [        SU R
                   S35      e[        U5        Xl        U(       a  X l        U$ )a  Decorator to register a function as the default action handler.

Example usage:

.. code-block:: python

    from cyclopts import App

    app = App()


    @app.default
    def main():
        print("Hello world!")


    app()

.. code-block:: console

    $ my-script
    Hello world!
r  rf   z"Default command previously set to rZ   )	r   r   rg   rh   ri   r   r$   r/   r   r  s      rM   r   r  p  sw    : ;4<<9==c3CDD+'*LTMaMaLbbc(dee"&N
rO   )r   parse_docstringr  c                    U R                   c  [        S5      e[        R                  " U R                   [        R
                  " U R                  R                  U5      U R                  U R                  US9$ )a  Assemble the argument collection for this app.

Parameters
----------
default_parameter: Parameter | None
    Default parameter with highest priority.
parse_docstring: bool
    Parse the docstring of :attr:`default_command`.
    Set to :obj:`True` if we need help strings, otherwise set to :obj:`False` for performance reasons.

Returns
-------
ArgumentCollection
    All arguments for this app.
zCannot assemble argument collection: no default command is registered. Use @app.default to register a default command, or access a specific subcommand's argument collection via app['command_name'].assemble_argument_collection().)r   r~   r  )
r   rK   r   _from_callabler.   combiner   r   ry   rx   )r   r   r  s      rM   r   App.assemble_argument_collection  sq    * 'k 
 "00  dnn>>@QR 11!33+
 	
rO   )r   r   r   c                    UUUS.nU R                  / US9   U R                  U5      u  pgpn
SSS5        WWWW	4$ ! , (       d  f       N= f)a>  Interpret arguments into a registered function, :class:`~inspect.BoundArguments`, and any remaining unknown tokens.

Parameters
----------
tokens: None | str | Iterable[str]
    Either a string, or a list of strings to launch a command.
    Defaults to ``sys.argv[1:]``
console: ~rich.console.Console
    Console to print help and runtime Cyclopts errors.
    If not provided, follows the resolution order defined in :attr:`App.console`.
error_console: ~rich.console.Console
    Console to print error messages.
    If not provided, follows the resolution order defined in :attr:`App.error_console`.
end_of_options_delimiter: str | None
    All tokens after this delimiter will be force-interpreted as positional arguments.
    If None, inherits from :attr:`App.end_of_options_delimiter`, eventually defaulting to POSIX-standard ``"--"``.
    Set to an empty string to disable.

Returns
-------
command: Callable
    Bare function to execute.

bound: inspect.BoundArguments
    Bound arguments for ``command``.

unused_tokens: list[str]
    Any remaining CLI tokens that didn't get parsed for ``command``.

ignored: dict[str, Any]
    A mapping of python-variable-name to annotated type of any
    parameter with annotation ``parse=False``.
    :obj:`~typing.Annotated` will be resolved.
    Intended to simplify :ref:`meta apps <Meta App>`.
)r   r   r   	overridesN)r   _parse_known_args)r   rp  r   r   r   r  r   rE   r  ignoredr   s              rM   parse_known_argsApp.parse_known_args  s]    X  +(@
	
 ^^B)^48<8N8Nv8V5GMA 5 }g55 54s	   ;
A	raise_on_unused_tokensr  c          	        ^^^ Tc  [        [        5       5        [        T5      mU nU R                  TSS9u  pEnU R                  TSS9u  mpgUS   m[	        [
        5         T(       aq  TS   [        US   R                  US   R                  -   5      ;   aB  US S nTS S mT(       a1  TS   [        US   R                  US   R                  -   5      ;   a  MB  S S S 5        US   mA0 nU R                  U5         TR                  R                  S5      =(       d    Sn	[        UU4S jU	 5       5      n	U R                  R                  S	S
S9n
[        TTR                  U
5      n Ub  [        TR                  TR                  -   5      nT Vs/ s H  oU;  d  M
  UPM     snTS S & U Vs/ s H  oU;  d  M
  UPM     snUS S & U R                  nUR                  =n(       a!  UR                  nUR                  =n(       a  M!  [        R                   " U5      R#                  TTR$                  S9n/ n['        5       nGO[)        U4S jTR                   5       5      (       ay  [+        T5      nUR                  =n(       a   [+        U5      nUR                  =n(       a  M   [        R                   " U5      R#                  TR$                  S9n/ n['        5       nGObTR,                  (       a  TR,                  n[/        U5        TR1                  5       nUR3                  SS9 Vs0 s H7  nUR4                  R6                  [9        UR4                  R:                  5      _M9     nn[=        TR,                  UUU	U
S9u  p TR>                   H  nU" S0 UR@                  D6  M      TR                  RL                   H(  nUR>                   H  nU" S0 UR@                  D6  M     M*     OVU(       a	  [O        US9eU R                  n[        R                   " U5      R#                  TTR$                  S9n/ n['        5       nU(       aO  U(       aH  U H9  n[Q        U5      (       d  M  URS                  S5      S   n[U        [W        USS9US9e   [Y        XS9eS S S 5        WWXxW4$ ! , (       d  f       GN= fs  snf s  snf s  snf ! [B        [D        [F        4 a0  n[I        URJ                  (       a  URJ                  S   OSTS9UeS nAff = f! [B        [D        [F        4 a0  n[I        URJ                  (       a  URJ                  S   OSWS9UeS nAff = f! [Z         aJ  nTR,                  Ul.        TUl/        T(       a  TUl0        UR$                  c  TRb                  Ul        e S nAff = f! , (       d  f       GN= f)NTrn  Frs  r   rS   c              3   >   >#    U  H  n[        UTT5      v   M     g 7frm   r  ).0rj   command_appr  s     rM   	<genexpr>(App._parse_known_args.<locals>.<genexpr>  s     R6a71k=AA6s   r   r  r<  r   c              3   ,   >#    U  H	  oT;   v   M     g 7frm   rS   )r  r  rp  s     rM   r  r  6  s     N4MD4Ms   rG  )r   r   r   )exception_messagers   )r  r   )r  )rp  r   =cli)keywordsource)r  r  )targetr  )2_log_framework_warning_detect_test_frameworkr!   r  r   r   rg  r   r   r   r  r  _get_help_flag_indexr   r   r\   	signaturebindr   r   anyrt   r   r/   r  	filter_by
field_infor   r   
annotationr   r   	argumentsAssertionErrorrK   ri   r)   argscommand_groupsr&   r    r`   r'   r1   r(   r%   r  rs   r  r   )r   rp  r  rv  r   apps_for_contextexecution_appsr  r  r   r   help_flag_indexflags_to_removetr   rE   r  argumentr   ecommand_groupr  r  r  s    `                    @@rM   r  App._parse_known_args  s~    >"#9#;<!&) "&!4!4VQU!4!VQ7;7J7J6gl7J7m4~ %R(j!
  M"$5r"--r0B0P0PP: % "0!4 -cr 2	  M"$5r"--r0B0P0PP: % " %R("$^^,-+6+@+@+H+H+S+YWYFR6RRF'+~~'='=>Xcg'='h$
 36;;Q;QSklOS".
 '*+*@*@;C\C\*\&]O,2 OFq6NF OF1I3@']=a_D\=']M!$"ooG)4)A)AA+A"-"8"8 *5)A)AA+A#--g6;;FKL_L_;`E$&M*<*>'NK4M4MNNN2;?G)4)A)AA+A"6{"C *5)A)AA+A $--g6;;KDWDW;XE$&M*<*>'"22"-"="=(1.9.V.V.X+ -@,I,IPU,I,V3,V %//446GH[H[HfHf6gg,V   3
 0F'77/)"5M0,y-8-B-B	 ) <EOO < .C
%1<1F1F1U1U1>1H1HI$-$@$@ 2I 2V )"5M"RR '+ooG$+$5$5g$>$C$C6[f[n[n$C$oE,.M2D2F/)m!.)%00$)KK$4Q$7E"4&+E%&H4G#  "/ /g[[k .~ }7JJJ_ "!B !P']*3 !/
IF y"1QRQWQWAFF1I]_ep"qwxxy !/
IF %"1?@vv!&&)2&3# $%%%2 ! &66# &3AO99$ + 9 9AIm .-s   !A7R&;A,V.()U	R8R8$
U.	R=;R=AUBU%BU)>S'U%S)AT+A8U'1U&
R58UT+TTUU$+UUU
V+!AV&&V++V..
V=)r   r   r   r   r   r   r   c                r   Uc  [        [        5       5        [        U5      nUUUUUUUS.R                  5        V	V
s0 s H  u  pU
c  M
  X_M     nn	n
U R	                  / US9    U R                  USS9u  ppn SSS5        WWW4$ s  sn
n	f ! [         Ga  nU R                  R                  S5      nU R                  R                  S5      nU R                  R                  S5      nU R                  R                  S	5      nUb  UOS
Ul        UUl	        UR                  c   eUb  U(       a  OOU R                  UUR                  S9  Ub  U(       a&  O UR                  R                  [        U5      5        Ub  U(       a  O [        R                  " S5        e SnAff = f! , (       d  f       GN4= f)aN  Interpret arguments into a function and :class:`~inspect.BoundArguments`.

Raises
------
UnusedCliTokensError
    If any tokens remain after parsing.

Parameters
----------
tokens: None | str | Iterable[str]
    Either a string, or a list of strings to launch a command.
    Defaults to ``sys.argv[1:]``.
console: ~rich.console.Console
    Console to print help and runtime Cyclopts errors.
    If not provided, follows the resolution order defined in :attr:`App.console`.
error_console: ~rich.console.Console
    Console to print error messages.
    If not provided, follows the resolution order defined in :attr:`App.error_console`.
print_error: bool | None
    Print a rich-formatted error on error.
    If :obj:`None`, inherits from :attr:`App.print_error`, eventually defaulting to :obj:`True`.
exit_on_error: bool | None
    If there is an error parsing the CLI tokens invoke ``sys.exit(1)``.
    Otherwise, continue to raise the exception.
    If :obj:`None`, inherits from :attr:`App.exit_on_error`, eventually defaulting to :obj:`True`.
help_on_error: bool | None
    Prints the help-page before printing an error.
    If :obj:`None`, inherits from :attr:`App.help_on_error`, eventually defaulting to :obj:`False`.
verbose: bool | None
    Populate exception strings with more information intended for developers.
    If :obj:`None`, inherits from :attr:`App.verbose`, eventually defaulting to :obj:`False`.
end_of_options_delimiter: str | None
    All tokens after this delimiter will be force-interpreted as positional arguments.
    If :obj:`None`, inherits from :attr:`App.end_of_options_delimiter`, eventually defaulting to POSIX-standard ``"--"``.
    Set to an empty string to disable.

Returns
-------
command: Callable
    Function associated with command action.

bound: inspect.BoundArguments
    Parsed and converted ``args`` and ``kwargs`` to be used when calling ``command``.

ignored: dict[str, Any]
    A mapping of python-variable-name to type-hint of any parameter with annotation ``parse=False``.
    :obj:`~typing.Annotated` will be resolved.
    Intended to simplify :ref:`meta apps <Meta App>`.
N)r   r   r   r   r   r   r   r  Tr  r   r   r   r   Fr  rz  )r  r  r!   rS  r   r  r%   r  r   root_input_tokensr   r   rC  r-   r   exit)r   rp  r   r   r   r   r   r   r   rO  vr  r   rE   r   r  r  s                    rM   
parse_argsApp.parse_args}  s   z >"#9#;<!&) $"/*!.!.",D eg
  AD 	 
 ^^B)^4040F0F+/ 1G 1-A 5. w&&M
* ! "nn44]C $ 6 6 G $ 6 6 G..00;'.':G	&,#yy,,,$1$==5OOFAIIO>"-"9;tIIOOM!$45$1$==4HHQK 54s6   	B
B#F'%BF$DFF$$F''
F6c                     [        U R                  R                  5      S:  =(       dA    U R                  SL=(       a,    [        U R                  R                  R                  5      S:  $ )zHCheck if this is a nested call (meta app pattern or same-app recursion).rz  N)r}  r   overrides_stackr   r   s    rM   _is_nested_callApp._is_nested_call  sO    4>>112Q6 
JJd"Ts4::+?+?+O+O'PST'T	
rO   )	r   r   r   r   r   r   r   r   r   c       	   	         Uc  [        [        5       5        [        U5      nUUUUUUU	U
S.R                  5        VVs0 s H  u  pUc  M
  X_M     nnnU R	                  5       (       a  UR                  SS5        U R                  X5         U R                  UUUS9u  pn[        [        S   U R                  R                  SSS	95      n [        XU5      nU R                  U5      sSSS5        $ s  snnf ! [         a+    U R                  (       a  [        R                   " S
5         Oe f = f SSS5        g! , (       d  f       g= f)a(	  Interprets and executes a command.

Parameters
----------
tokens : None | str | Iterable[str]
    Either a string, or a list of strings to launch a command.
    Defaults to ``sys.argv[1:]``.
console: ~rich.console.Console
    Console to print help and runtime Cyclopts errors.
    If not provided, follows the resolution order defined in :attr:`App.console`.
error_console: ~rich.console.Console
    Console to print error messages.
    If not provided, follows the resolution order defined in :attr:`App.error_console`.
print_error: bool | None
    Print a rich-formatted error on error.
    If :obj:`None`, inherits from :attr:`App.print_error`, eventually defaulting to :obj:`True`.
exit_on_error: bool | None
    If there is an error parsing the CLI tokens invoke ``sys.exit(1)``.
    Otherwise, continue to raise the exception.
    If :obj:`None`, inherits from :attr:`App.exit_on_error`, eventually defaulting to :obj:`True`.
help_on_error: bool | None
    Prints the help-page before printing an error.
    If :obj:`None`, inherits from :attr:`App.help_on_error`, eventually defaulting to :obj:`False`.
verbose: bool | None
    Populate exception strings with more information intended for developers.
    If :obj:`None`, inherits from :attr:`App.verbose`, eventually defaulting to :obj:`False`.
end_of_options_delimiter: str | None
    All tokens after this delimiter will be force-interpreted as positional arguments.
    If :obj:`None`, inherits from :attr:`App.end_of_options_delimiter`, eventually defaulting to POSIX-standard ``"--"``.
    Set to an empty string to disable.
backend: Literal["asyncio", "trio"] | None
    Override the async backend to use (if an async command is invoked).
    If :obj:`None`, inherits from :attr:`App.backend`, eventually defaulting to "asyncio".
    If passing backend="trio", ensure trio is installed via the extra: `cyclopts[trio]`.
result_action: ResultAction | None
    Controls how command return values are handled. Can be a predefined literal string
    or a custom callable that takes the result and returns a processed value.
    If :obj:`None`, inherits from :attr:`App.result_action`, eventually defaulting to "print_non_int_return_int_as_exit_code".
    See :attr:`App.result_action` for available modes.

Returns
-------
return_value: Any
    The value the command function returns.
Nr   r   r   r   r   r   r   r   r   return_valuer   r   r   r   r   r<     )r  r  r!   rS  r  r  r   r  r   r   r  rC   _handle_result_actionKeyboardInterruptr   r   r  )r   rp  r   r   r   r   r   r   r   r   r   rO  r  r  r   rE   r   resolved_backendrL   s                      rM   __call__App.__call__  sV   v >"#9#;<!&)
 $"/*!.!.""!.	 eg	
	  AD	 	 
 !!  .A^^F. $)A !0 !GA  $G,=$>@V@VW`kt@V@uv1'BRS11&9 /.%
: % 33HHSM	! /..s6   	C3C3A D;C991D.*D;,D..D;;
E	c       	   	        #    Uc  [        [        5       5        [        U5      nUUUUUUU	U
S.R                  5        VVs0 s H  u  pUc  M
  X_M     nnnU R	                  5       (       a  UR                  SS5        U R                  X5         U R                  UUUS9u  pn [        R                  " U5      (       a%  U" UR                  0 UR                  D6I Sh  vN nOU" UR                  0 UR                  D6nU R                  U5      sSSS5        $ s  snnf  NA! [         a+    U R                  (       a  [        R                   " S5         Oe f = f SSS5        g! , (       d  f       g= f7f)a  Async equivalent of :meth:`__call__` for use within existing event loops.

This method should be used when you're already in an async context
(e.g., Jupyter notebooks, existing async applications) and need to
execute a Cyclopts command without creating a new event loop.

Parameters
----------
tokens : None | str | Iterable[str]
    Either a string, or a list of strings to launch a command.
    Defaults to ``sys.argv[1:]``.
console: ~rich.console.Console
    Console to print help and runtime Cyclopts errors.
    If not provided, follows the resolution order defined in :attr:`App.console`.
error_console: ~rich.console.Console
    Console to print error messages.
    If not provided, follows the resolution order defined in :attr:`App.error_console`.
print_error: bool | None
    Print a rich-formatted error on error.
    If :obj:`None`, inherits from :attr:`App.print_error`, eventually defaulting to :obj:`True`.
exit_on_error: bool | None
    If there is an error parsing the CLI tokens invoke ``sys.exit(1)``.
    Otherwise, continue to raise the exception.
    If :obj:`None`, inherits from :attr:`App.exit_on_error`, eventually defaulting to :obj:`True`.
help_on_error: bool | None
    Prints the help-page before printing an error.
    If :obj:`None`, inherits from :attr:`App.help_on_error`, eventually defaulting to :obj:`False`.
verbose: bool | None
    Populate exception strings with more information intended for developers.
    If :obj:`None`, inherits from :attr:`App.verbose`, eventually defaulting to :obj:`False`.
end_of_options_delimiter: str | None
    All tokens after this delimiter will be force-interpreted as positional arguments.
    If :obj:`None`, inherits from :attr:`App.end_of_options_delimiter`, eventually defaulting to POSIX-standard ``"--"``.
    Set to an empty string to disable.
backend: Literal["asyncio", "trio"] | None
    Override the async backend to use (if an async command is invoked).
    If :obj:`None`, inherits from :attr:`App.backend`, eventually defaulting to "asyncio".
    If passing backend="trio", ensure trio is installed via the extra: `cyclopts[trio]`.
result_action: ResultAction | None
    Controls how command return values are handled. Can be a predefined literal string
    or a custom callable that takes the result and returns a processed value.
    If :obj:`None`, inherits from :attr:`App.result_action`, eventually defaulting to "print_non_int_return_int_as_exit_code".
    See :attr:`App.result_action` for available modes.

Returns
-------
return_value: Any
    The value the command function returns.

Examples
--------
.. code-block:: python

    import asyncio
    from cyclopts import App

    app = App()


    @app.command
    async def my_async_command():
        await asyncio.sleep(1)
        return "Done!"


    # In an async context (e.g., Jupyter notebook or existing async app):
    async def main():
        result = await app.run_async(["my-async-command"])
        print(result)  # Prints: Done!


    asyncio.run(main())
Nr  r   r  r  r  )r  r  r!   rS  r  r  r   r  r\   rp   r  r{   r  r  r   r   r  )r   rp  r   r   r   r   r   r   r   r   r   rO  r  r  r   rE   r   rL   s                     rM   	run_asyncApp.run_asyncQ  sh    n >"#9#;<!&)
 $"/*!.!.""!.	 eg	
	  AD	 	 
 !!  .A^^F. $)A !0 !GA..w77#*EJJ#G%,,#GGF$ejjAELLAF11&9 /.%
6 H
 % 33HHSM	!! /..se   >E5 	DD;E5E$$:D"D 1D"E5 D""1EE$EE$	E5$
E2.E5r  )r   c                L   SSK JnJn  SSKJn  [        U5      nU R                  U5      u  pgnUS   n	SU0n
U R                  XzS9   U	R                  nU	R                  c	  U" X5      nO#U	R                  (       a  U	R                  S-   nOSnU	R                  R                  S	[        S
9nU" X5      nU R                  X5      nU	R                  R                  SU" 5       S
9n[        US5      (       a  UR                  X"R                  U5        OU(       a  UR!                  U5        [        US5      (       a  UR#                  X"R                  U5        OU(       a  UR!                  U5        U H?  u  nnU(       a  UR$                  OSnUc  Un['        SU5      nU" X"R                  U5        MA     U	R                  R                  S5      =n(       a7  SSK Jn  UR!                  5         UR+                  UUS9nUR!                  U5        SSS5        g! , (       d  f       g= f)ap  Print the help page.

Parameters
----------
tokens: None | str | Iterable[str]
    Tokens to interpret for traversing the application command structure.
    If not provided, defaults to ``sys.argv``.
console: ~rich.console.Console
    Console to print help and runtime Cyclopts errors.
    If not provided, follows the resolution order defined in :attr:`App.console`.
r   )
format_docformat_usage)DefaultFormatterrs  r   r  N
r   r<  r   render_usagerender_descriptionr@   r   r:  r>  )r@  r  r  cyclopts.help.formattersr   r!   r  r   r   r   r  rA  _assemble_help_panelshasattrr  optionsrC  r  r   r   r;  rB  )r   rp  r   r  r  r   r  rw  r   executing_appr  r   r   descriptionhelp_panels_with_groupsdefault_formatterr   panel	formatterr   r;  epilogues                         rM   r   App.help_print  s   " 	;=!&)!%!4!4V!<QR)	^^D^6#++G ""*$T9$$%++d2 (1199-Ra9bK$]@K '+&@&@&U# !. 7 7 ? ?@P[k[m ? n(.99!..wOe$ (*>??!44Woo{[k* !8u49E00t	$ 1I )<	'??E: !8 !. 7 7 ? ? PP}P4%11-1Th'[ 766s   GH
H#r*   r?   c           
      2   SSK Jn  SSK Jn  SSKJnJnJnJn  U R                  U5      u  pnU
S   nUR                  R                  SU[        5      n0 n[        U5       H  n[        U5       H  u  nnUR                  (       d  M   XR                     u  nnUR"                  (       aR  UR%                  UR"                  US	S
9nUR&                  (       a  U" UR&                  U" 5       U5      Ul        OUUl        UR(                  R+                  U" UUS95        M     M     U R-                  U
5      nU GH  nUR.                  (       d  M  UR1                  S	S9nUR                  R                  S5      =(       d    Sn[3        S U 5       5      nU H  nU H  nUR5                  U	U5      n[7        UR8                  R:                  [2        5      (       d   e[<        R>                  " UR8                  [=        / UR8                  R:                  QUP7S95      Ul        M     M     UR@                   H  nUR                  (       d  M  URC                  US9nU(       d  M.  URE                  UR                  S5      u  nnU" UUU5      nU(       a  SUl#        UR(                  UR(                  -   Ul        UR&                  (       a:  UR&                  (       a(  U" UR&                  U" 5       UR&                  5      Ul        OUR&                  Ul        UU4XR                  '   M     GM     URI                  5        Vs/ s H  nUS   PM
     nnURI                  5        Vs/ s H  nUS   PM
     nn/ n [K        UU5      u  n!n"[M        U!U"SS9 HI  u  nn#U#RO                  5         U#RF                  S:X  a  U#RQ                  5         U RS                  UU#45        MK     U $ ! [          a%    U" UR                  SS9nUU4XR                  '    GNrf = fs  snf s  snf )Nr   )r*   )NewLine)r?   r;  create_parameter_help_panelformat_command_entriesrs  r   r   )titler?  T)r?  force_empty_endr>  )r  r   rS   c              3   z   #    U  H1  n[        U[        5      (       d  M  UR                  (       d  M-  Uv   M3     g 7frm   )rg   r#   r   )r  rj   s     rM   r  ,App._assemble_help_panels.<locals>.<genexpr>V  s#     T7ajC6HQVV7s   ;;	;)env_var)r   NN	parameterrz  F)strict)*r#  r*   r  r@  r?   r;  r  r  r  r   r  rA  r   r,   r   r   r   r   rB  r	  entriesrt  r  r   r  r  _convert_argumentrg   r  r  r.   r  groupsr  r   r?  r  r+   zip_remove_duplicates_sortr   )$r   rp  r   	RichGroupr  r?   r;  r  r  r  r  r   r  panelsr   r   apps_with_namescommand_panel
group_helpapps_for_paramsr  configsenv_configsr  
env_configr  group_argument_collectionexisting_panel	new_panelrj   r  help_panelsr  sorted_groupssorted_panels
help_panels$                                       rM   r  App._assemble_help_panels  s   
 	4(	
 	
 ,0+>+>v+F(q$R(!++33M;P_`57 "+.F*9&*A&zz@'-jj'9$A}
 ::!+!7!7

;hl!7!mJ$004=m>W>WY`Ybdn4o14>1 %%,,-CO\g-hi) +B /4 66~F%F))"("E"EVZ"E"[ -3,<,<,D,DY,O,USUGT7TTK/"-J(::=(SG%h&8&8&@&@%HHHH)2):): **!*PH,>,>,F,F*P*PQ*H& #. 0 -33zz,?,I,IPU,I,V)0$*JJuzz<$H!>7?XZef	!,7N)(1(9(9N<R<R(RI% ,,)554= . : :GIyG\G\5I1 1?0J0J	-&+Y%7zz"- 4% &T !'01!A$0%+]]_5_qt_5'26;'G$}!$]M%!PE:))+  I-  "JJz*+ "Q 
S   @$-EJJy$QM*/)?F::&@| 15s   O>P!P+PPoutput_formatr>   	recursiveinclude_hiddenheading_levelflatten_commandsc           	          SSK JnJnJn  SSKJn	  U" U5      nUS:X  a  U" U UUUUS9n
U
$ US:X  a  U	" U UUUUS9n
U
$ US:X  a  U" U UUUUSS	9n
W
$ )
a  Generate documentation for this CLI application.

Parameters
----------
output_format : DocFormat
    Output format for the documentation. Accepts "markdown"/"md", "html"/"htm",
    or "rst"/"rest"/"restructuredtext". Default is "markdown".
recursive : bool
    If True, generate documentation for all subcommands recursively.
    Default is True.
include_hidden : bool
    If True, include hidden commands/parameters in documentation.
    Default is False.
heading_level : int
    Starting heading level for the main application title.
    Default is 1 (single # for markdown, = for RST).
flatten_commands : bool
    If True, generate all commands at the same heading level instead of nested.
    Default is False.

Returns
-------
str
    The generated documentation.

Raises
------
ValueError
    If an unsupported output format is specified.

Examples
--------
>>> app = App(name="myapp", help="My CLI Application")
>>> docs = app.generate_docs()  # Generate markdown as string
>>> html_docs = app.generate_docs(output_format="html")  # Generate HTML
>>> rst_docs = app.generate_docs(output_format="rst")  # Generate RST
>>> # To write to file, caller can do:
>>> # Path("docs/cli.md").write_text(docs)
r   )generate_markdown_docsgenerate_rst_docsnormalize_format)generate_html_docsrG   )r4  r5  r6  r7  htmlr   F)r4  r5  r6  r7  no_root_title)cyclopts.docsr9  r:  r;  cyclopts.docs.htmlr<  )r   r3  r4  r5  r6  r7  r9  r:  r;  r<  r  s              rM   generate_docsApp.generate_docs  s    ^	
 	

 	:(7J&(#-+!1C2 
% f$$#-+!1C" 
 e###-+!1#C 
rO   )	prog_nameshellrC  rD  )zshbashfishc                h   UcV  U R                   (       d  [        S5      e[        U R                   [        5      (       a  U R                   S   OU R                   nUc  SSKJn  U" 5       nUS:X  a  SSKJn  U" X5      $ US:X  a  SSKJn  U" X5      $ US:X  a  SSK	Jn  U" X5      $ [        SU 35      e)	a  Generate shell completion script for this application.

Parameters
----------
prog_name : str | None
    Program name for completion. If None, uses first name from app.name.
shell : Literal["zsh", "bash", "fish"] | None
    Shell type. If None, automatically detects current shell.
    Supported shells: "zsh", "bash", "fish".

Returns
-------
str
    Complete shell completion script.

Examples
--------
Auto-detect shell and generate completion:

>>> app = App(name="myapp")
>>> script = app.generate_completion()
>>> Path("_myapp").write_text(script)

Explicitly specify shell type:

>>> script = app.generate_completion(shell="zsh")

Raises
------
ValueError
    If app has no name or shell type is unsupported.
ShellDetectionError
    If shell is None and auto-detection fails.
z2App must have a name to generate completion scriptr   detect_shellrE  )generate_completion_scriptrF  rG  zUnsupported shell: )
r   rK   rg   r  cyclopts.completionrJ  cyclopts.completion.zshrK  cyclopts.completion.bashcyclopts.completion.fish)r   rC  rD  rJ  rK  s        rM   generate_completionApp.generate_completion  s    P 99 !UVV(2499e(D(D		!$))I=8 NEE>J-d>>f_K-d>>f_K-d>>25':;;rO   )rD  outputadd_to_startuprR  rS  c                    SSK Jn  Uc  U" 5       nSSKJnJn  U R                  US9nUc  U" XR                  S   5      nUR                  R                  SSS9  UR                  U5        U(       a  US;   a  U" X R                  S   U5        U$ )a7  Install shell completion script to appropriate location.

Generates and writes the completion script to a shell-specific location.

Parameters
----------
shell : Literal["zsh", "bash", "fish"] | None
    Shell type for completion. If not specified, attempts to auto-detect current shell.
output : Path | None
    Output path for the completion script. If not specified, uses shell-specific default:
    - zsh: ~/.zsh/completions/_<prog_name>
    - bash: ~/.local/share/bash-completion/completions/<prog_name>
    - fish: ~/.config/fish/completions/<prog_name>.fish
add_to_startup : bool
    If True (default), adds source line to shell RC file to ensure completion is loaded.
    Set to False if completions are already configured to auto-load.

Returns
-------
Path
    Path where the completion script was installed.

Examples
--------
Auto-detect shell and install:

>>> app = App(name="myapp")
>>> path = app.install_completion()

Install for specific shell:

>>> path = app.install_completion(shell="zsh")

Install to custom path:

>>> path = app.install_completion(output=Path("/custom/path"))

Install without modifying RC files:

>>> path = app.install_completion(shell="bash", add_to_startup=False)

Raises
------
ShellDetectionError
    If shell is None and auto-detection fails.
ValueError
    If shell type is unsupported.
r   rI  )add_to_rc_fileget_default_completion_path)rD  T)parentsexist_ok)rF  rE  )
cyclopts.completion.detectrJ  cyclopts.completion.installrU  rV  rP  r   parentmkdir
write_text)r   rD  rR  rS  rJ  rU  rV  script_contents           rM   install_completionApp.install_completion	  s    n 	<= NE[111>>0		!EFD48.) e6699Q<7rO   c                 `    SSK Jn  U" U R                  U5      nU R                  " U4SU0UD6  g)a  Register a command for installing shell completion.

This is a convenience method that creates a command which calls
:meth:`install_completion`. For more control over the command
implementation, users can manually define their own command.

Parameters
----------
name : str | Iterable[str]
    Command name(s) for the install completion command.
    Defaults to "--install-completion".
add_to_startup : bool
    If True (default), adds source line to shell RC file to ensure completion is loaded.
    Set to False if completions are already configured to auto-load.
**kwargs
    Additional keyword arguments to pass to :meth:`command`.
    Can be used to customize the command registration (e.g., `help`, `group`, `help_flags`, `version_flags`).

Examples
--------
Register install-completion command:

>>> app = App(name="myapp")
>>> app.register_install_completion_command()
>>> app()  # Now responds to: myapp --install-completion

Use a custom command name:

>>> app.register_install_completion_command(name="--setup-completion")

Customize help text:

>>> app.register_install_completion_command(help="Install shell completion for myapp.")

Customize command registration:

>>> app.register_install_completion_command(group="Setup", help_flags=[])

Install without modifying RC files:

>>> app.register_install_completion_command(add_to_startup=False)

See Also
--------
install_completion : The underlying method that performs the installation.
r   )!create_install_completion_commandr   N)rZ  rb  r_  r   )r   r   rS  r{   rb  
command_fns         rM   #register_install_completion_command'App.register_install_completion_commandf	  s2    h 	R6t7N7NP^_
Z5d5f5rO   promptquit
dispatcherzConsole | Nonec                 l   [         R                  S:X  a  [        S5        O[        S5        Uc  SS/n[        U[        5      (       a  U/nS nUc  Un0 n	Ub  XiS'   Ub  XIS	'     [        U5      n
[        U
5      nU(       d  M!  US
   U;   a  g U R                  X5         U R                  " U4XES.UD6u  pnU" XU5      nU R                  USS9  SSS5        Mx  ! [         a     gf = f! , (       d  f       N = f! [         a     N/[         a!    [        [        R                  " 5       5         NXf = f)a  Create a blocking, interactive shell.

All registered commands can be executed in the shell.

Parameters
----------
prompt: str
    Shell prompt. Defaults to ``"$ "``.
quit: str | Iterable[str]
    String or list of strings that will cause the shell to exit and this method to return.
    Defaults to ``["q", "quit"]``.
dispatcher: Dispatcher | None
    Optional function that subsequently invokes the command.
    The ``dispatcher`` function must have signature:

    .. code-block:: python

        def dispatcher(command: Callable, bound: inspect.BoundArguments, ignored: dict[str, Any]) -> Any:
            return command(*bound.args, **bound.kwargs)

    The above is the default dispatcher implementation.
console: Console | None
    Rich Console to use for output. If :obj:`None`, uses :attr:`App.console`.
exit_on_error: bool
    Whether to call ``sys.exit`` on parsing errors. Defaults to :obj:`False`.
result_action: ResultAction | None
    How to handle command return values in the interactive shell.
    Defaults to ``"print_non_int_return_int_as_exit_code"`` which prints non-int results
    and returns int/bool as exit codes without calling sys.exit.
    If :obj:`None`, inherits from :attr:`App.result_action`.
`**kwargs`
    Get passed along to :meth:`parse_args`.
posixz(Interactive shell. Press Ctrl-D to exit.z:Interactive shell. Press Ctrl-Z followed by Enter to exit.Nqrg  c                 :    U " UR                   0 UR                  D6$ rm   )r  r{   )r   rE   r   s      rM   default_dispatcher1App.interactive_shell.<locals>.default_dispatcher	  s    EJJ7%,,77rO   r   r   r   )r   r   %print_non_int_return_int_as_exit_coder<  )osr   rC  rg   r   inputEOFErrorr!   r   r  r  r%   r  	traceback
format_exc)r   rf  rg  rh  r   r   r   r{   rm  r  
user_inputrp  r   rE   r  rL   s                   rM   interactive_shellApp.interactive_shell	  sX   V 77g<= NO<=DdC  6D	8 +J	$)6o&$+j!"6]
 &j1FayD .^^F6.2oo/(//PV/+GG (@F..v@g.h 7    76 !  .i**,-.sH   %C C=  2C,C= 
C)(C),
C:6C= :C= =
D3	'D32D3rL   r=  c                 z   ^  SSK Jn  [        [        T R                  R                  SUS95      nU" XU 4S j5      $ )aF  Handle command result based on result_action.

Parameters
----------
result : Any
    The command's return value.
fallback : ResultAction
    The fallback result_action if none is configured. Defaults to "print_non_int_sys_exit".

Returns
-------
Any
    Processed result based on action (may call sys.exit() and not return).
r   )handle_result_actionr   r<  c                 :   > TR                   R                  U 5      $ rm   )r   rC  )rj   r   s    rM   <lambda>+App._handle_result_action.<locals>.<lambda>
  s    dll>P>PQR>SrO   )cyclopts._result_actionry  r   rA   r   r  )r   rL   r=  ry  actions   `    rM   r  App._handle_result_action	  s=     	ANN""?X"F

 $F4STTrO   c                 N    U R                   R                  UR                   5        g)zCopy over all commands from another :class:`App`.

Commands from the meta app will **not** be copied over.

Parameters
----------
app: cyclopts.App
    All commands from this application will be copied over.
N)r   r   )r   rs   s     rM   r   
App.update
  s     	cmm,rO   c                    0 nU R                    Hl  nUR                  (       d  M  [        XR                  5      n[	        U5      [	        UR
                  5      :w  d  X2R
                  :w  d  M^  X1UR                  '   Mn     SR                  S UR                  5        5       5      n[	        U 5      R                   SU S3$ )zOnly shows non-default values.r{  c              3   6   #    U  H  u  pU S U< 3v   M     g7f)r  NrS   )r  rO  r  s      rM   r  App.__repr__.<locals>.<genexpr>*
  s     L7Ktq1QEl7Ks   ())
__attrs_attrs__r   getattrr   rl  r   r   r~  rS  rT   )r   non_defaultsar  r  s        rM   __repr__App.__repr__
  s    %%A66ff%AAw$qyy/)Q))^()QWW% & IIL|7I7I7KLL	t*%%&a	{!44rO   )r   r   r   r   r   ry   rw   rx   r   r   r   r   r   r   r   r   r   r   r   r   )rI   r=   )z0.0.0rm   )T)rI   r   )rI   rh   r  )rG   TFrz  F)z--install-completionT)z$ NNNFN)print_non_int_sys_exitrs   rh   )rT   rU   rV   rW   r   r6   r   r   r  __annotations__r   r   r9   r   rk   r   r   r   r   r.   r   rf  r   r   ro   r   r   r   boolr   r   r   r   r   r   r   r   r   r   r*   r   ry   rx   rw   r8   r   r   r7   r   r   r   r   r   r   r   r5   r   r   rN   r   rA   rB   r   r   r   r   r   r   r2   r   r   rl  r   r   r   r   r   r   r   propertyr   setterr   r   r   r~   r}   r   r   r   r   r   r   r   r+  r6  rE  r   rr   rq   rP  rV  r[  rZ  r`  rc  r   ri  r   r  r   r  r  r   rD   objectr   r   r  r\   BoundArgumentsr  r  r  r  r  r  r   r  intrA  rP  r   r_  rd  r0   rv  r  r   r  rX   rS   rO   rM   rh   rh     s    +0FVq*rE4#:c3h'rd&9E3:9d+E3:+ +0$+E4#:c3h'  27tOhrv1wOXc3h'$.w*/d*Ky4'K 	-			 
DKsCx2DEsJ
K	L
8T%[%S/;MNPSST
U	V	 Z_dZGTCZ(38,,xYsCQT}=U8U/VV  +0$	+NC(3-'  tT2D$2$)$I$VHhy!V*/dRa*bNHY'b (-4 $	(Kx}$  ejdeKYZ]aa  "'tT!BM4$;B %dD AM3:AgldhNG\]`dd  49Qcmq3rE53;us{C/00r ,1"	,eckD(  -2 "	-us{T)  +0"	+OUS[4'  +0HYcg*hItHS#X&'h384OXseSj)D0  $	Is  ,1t+LcDjL$T4@K@!&tT!BM4$;B t<GTD[<(-dD(II16tT1RGW&'$.RPU 8$QNE$(: ;_LM  ?D*?M<"44t;  165$0OItC,,-O ',&EUE"t<E8E?<$)ud$CL(5/C-2tRW-Xd
X DIe]binCod!2T%[!@o .3t-Lx	*L38eT3RXi0RUGHQU4VWIxW3(# " # #         BeCHo B B" % %
 & & & &
 ' ' $ $
 % % 1 1 ]]  c  4 
[[  X X % % C C __3 3 
d3:&6 
 
 & & ^^ x	2     , , &Xi%8 & & IzD'8 I I3C 3c 3j;S ;8ICV ;[_ ;( KO=8I.	0FFG= 
=8 KO=8I.	0FFG= 
=:  &4U
#3 &Ps u @( s  	c 	d 	'*(3- '*R   .2w@ !	w@s
Xc]*w@
 
uS#Xj 149<	=w@r#huo #$u+ #J:$u+ :tCy :UYZ]U^ :B  ,0
 -1 Sj8C=(
 czHSM)  
   +/
 -1 Sj8C=(
 czHSM)  
1#q&	   ,0
 -1 Sj8C=(
 czHSM)  
  #+/Q
 -1QX^Q Sj8C=(Q
 czHSM)Q Q 
Xqc1f		$Qp 
 04	 CH%,	
 
    04	 CH%,	
 
1#q&	  + 04	+X+ CH%,	+
 
Xqc1f	+` /3 %	!
 %t+!
 	!

 
!
J .236 (,-1/336s
Xc]*36 )$	36
  	*36 #&*36 
xS!7#9#949d3PS8nT	U36n .2FK (-	FKs
Xc]*FK !%	FK
 
xS!7#9#949d3PS8nVhh	iFKT .2i' (,-1#'%)%)#/3i's
Xc]*i' )$	i'
  	*i' D[i' d{i' d{i' i' #&*i' 
x//c3h?	@i'V
 
 .2a (,-1#'%)%)#/359-1as
Xc]*a )$	a
  	*a D[a d{a d{a a #&*a *+d2a $d*a 
aJ .2@ (,-1#'%)%)#/359-1@s
Xc]*@ )$	@
  	*@ D[@ d{@ d{@ @ #&*@ *+d2@ $d*@ 
@H PTF( KO	F($*x}4iU6KKLF( 8I.	0FFG	F(
 
F(Phs
Xc]*h 
eHW%{23	4	hX &0$!&R"R R 	R
 R R 
Rn !%7;	?< :?< ,-4	?<
 
?<H 8<"#J ,-4J t	J
 J 
J\ %;#76HSM!76 76
 
76v +/(,$(#-1Z.Z. Sj8C=(Z. %	Z.
 "Z. Z. $d*Z. 
Z.xUC U< Ugj U0
-5rO   c                 B   S nU(       a)  [        [        5         U R                  U5      nS S S 5        U HA  n[        [        5         U R                  U5      nUb  XS:  a   S S S 5          U$  S S S 5        MC     S nU$ ! , (       d  f       NY= f! , (       d  f       Mi  = frm   )r   rK   index)rp  r   r   delimiter_index	help_flagr  s         rM   r  r  .
  s    Oj!$ll+CDO "  	j!LL+E&%*A "! L +B "!   L "! "!s   A>B>
B
B	c                       \ rS rSrSrSrSrg)TestFrameworki?
  r   pytestrS   N)rT   rU   rV   rW   UNKNOWNPYTESTrX   rS   rO   rM   r  r  ?
  s    GFrO   r  c                      S[         R                  ;   a0  [        R                  R	                  S5      b  [
        R                  $ [
        R                  $ )zDetects if we are currently being ran in a test framework.

Returns
-------
TestFramework
    Name of the testing framework. Returns an empty string if not testing
    framework discovered.
r  PYTEST_VERSION)r   r  rp  environr   r  r  r  rS   rO   rM   r  r  D
  s;     3;;2::>>2B#C#O###$$$rO   	frameworkc                    U [         R                  :X  a  gSSKn[        R                  " 5        GH  nUR
                  nUR                  n[        R                  " U5      nUb  Uc  M:  UR                  R                  S5      S   nUS:X  a  M`  SUR                  ;  a  Mr  UR                  S   n0 UR                  EUR                  En/ n	UR                  5        H  u  pXL d  M  U	R                  U
5        M     [        U	5      S:w  a  Sn
OU	S   n
SU R                   S	U
 S
3nUR!                  [#        U5      SS9    g   g)zLog a warning message for a given testing framework.

Intended to catch developers invoking their app during unit-tests
without providing commands and erroneously reading from :obj:`sys.argv`.

TO ONLY BE CALLED WITHIN A CYCLOPTS.APP METHOD.
Nr   rZ   r[   r   rz  rs   zGCyclopts application invoked without tokens under unit-test framework "z". Did you mean "z([])"?r:   )
stacklevel)r  r  warningsr\   r]   r_   f_backr^   rT   r`   f_localsr   rS  r   r}  rH   warnUserWarning)r  r  ra   r_   r  calling_modulecalling_module_namecalled_cyclopts_app_instancecandidate_variablesmatched_app_variablesvar_namevar_instancemessages                rM   r  r  W
  sO    M)))

 **62!V^,55;;C@C*, '',~~f'=$E!1!1EV__E "&9&?&?&A"H;%,,X6 'B $%*H,Q/H[\e\k\k[ll}  G  ~H  HN  Ok'*q9;  rO   )rs   rh   ru   rh   rI   N)TTr  ){r1  r\   rp  r   rs  collections.abcr   r   r   r   r   
contextlibr   r	   enumr
   r  r   r   	itertoolsr   pathlibr   typesr   typingr   r   r   r   r   r   r   r   r   attrsr   r   r   cyclopts.annotationsr   cyclopts.app_stackr   cyclopts.argumentr   r  r   r    r!   cyclopts.command_specr"   cyclopts.config._envr#   cyclopts.exceptionsr$   r%   r&   r'   r(   r)   cyclopts.groupr*   r+   cyclopts.group_extractorsr,   cyclopts.panelr-   cyclopts.parameterr.   r/   cyclopts.protocolsr0   cyclopts.tokenr1   cyclopts.utilsr2   r3   r4   r5   r6   r7   r8   r9   version_infor3  readliner#  r=   cyclopts.docs.typesr>   r@  r?   cyclopts.help.protocolsr@   r}  rA   rB   cyclopts._runrC   rD   rF   rA  r  rN   r  rQ   rd   rk   rt   rz   r   r   r   r   r   r   r   rh   r  r  r  r  r  rS   rO   rM   <module>r     sH     	 
  M M    (   
 
 
 ) ( 2 ' 0 R R - $  . 5 ( : )  	 	 	 gk  
 $-'5 D 2CxS)*CLD3J#$> 5c?UYCY "	) 	.!)(F4S> Fu FQU F$7s 7s 74 BF%	%%	#"
"#%P	#$*u"4   g$5 g$5 g$5TI#PT* "C 
 % % %$ )m ) ) )qP s   =H
H