
    lKj                         d dl Z d dlmZmZ d dlmZmZmZ d dlm	Z	 ed   eegef   z  Z
e
ee
   z  Zddededefd	Zded
edeegdf   defdZy)    N)CallableIterable)AnyLiteralcast)is_iterable)return_valuecall_if_callable%print_non_int_return_int_as_exit_code!print_str_return_int_as_exit_codeprint_str_return_zero&print_non_none_return_int_as_exit_codeprint_non_none_return_zero!return_int_as_exit_code_else_zeroprint_non_int_sys_exitsys_exitreturn_nonereturn_zeroprint_return_zerosys_exit_zeroprint_sys_exit_zeroresultdefaultreturnc                 `    t        | dd      }t        |      rt        t         |             S |S )ay  Resolve the return code for ``result``.

    If ``result`` defines ``__cyclopts_returncode__`` (a zero-argument callable),
    its value is used. Otherwise ``default`` is returned.

    Custom ``result_action`` callables can use this helper to honor the
    ``__cyclopts_returncode__`` protocol consistently with the built-in actions.

    Parameters
    ----------
    result : Any
        The command's return value.
    default : int
        Fallback exit code when ``result`` doesn't define a callable
        ``__cyclopts_returncode__``. Defaults to ``0``.

    Returns
    -------
    int
        The resolved return code.
    __cyclopts_returncode__N)getattrcallabler   int)r   r   returncode_fns      h/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/cyclopts/_result_action.pyresolve_returncoder"      s/    , F$=tDMC))N    actionprint_fnc                    t        |      r+t        t        t           |      D ]  }t	        | ||      }  | S t        |      r ||       S |xdk(  r t        | t              rt        j                  | rdnd       yt        | t              rt        j                  |        y| ' ||        t        j                  t        |              yt        j                  t        |              yxdk(  r | S xdk(  r t        |       r |        S | S xdk(  rp t        | t              rt        j                  | rdnd       yt        | t              rt        j                  |        yt        j                  t        |              yxdk(  rI t        | t              r| rdS dS t        | t              r| S |  ||        t        |       S t        |       S xd	k(  rW t        | t              r ||        t        |       S t        | t              r| rdS dS t        | t              r| S t        |       S xd
k(  r$ t        | t              r ||        t        |       S xdk(  r> |  ||        t        | t              r| rdS dS t        | t              r| S t        |       S xdk(  r |  ||        t        |       S xdk(  r4 t        | t              r| rdS dS t        | t              r| S t        |       S xdk(  r yxdk(  r t        |       S xdk(  r  ||        t        |       S xdk(  r  t        j                  t        |              ydk(  r' ||        t        j                  t        |              y	 t        )u  Handle command result based on result_action.

    When ``action`` is a sequence, actions are applied left-to-right in a pipeline,
    where each action receives the result of the previous action. For example,
    with ``result_action=[uppercase, add_greeting]``:

        result → uppercase(result) → add_greeting(uppercase(result))

    Parameters
    ----------
    result : Any
        The command's return value.
    action : ResultAction
        The action (or sequence of actions) to take with the result.
        If a sequence, actions are chained left-to-right.
    print_fn : Callable[[Any], None]
        Function to call to print output (e.g., console.print).

    Returns
    -------
    Any
        Processed result based on action (may call sys.exit() and not return).
    r   r      Nr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   ResultActionSinglehandle_result_actionr   
isinstanceboolsysexitr   r"   str
ValueError)r   r$   r%   single_actions       r!   r)   r)   ;   s   8 6!(+=">GM)&-JF Hf~
%&$'f!,FC( # +F34+F34MxM&$'f!,FC( +F344&$'"q))FC(# )&11)&110&#& )&11FD)"q))FC()&11$&#& %f--5! &$'"q))FC(%f--)! %f--0&$'"q))FC()&11%f-- V%f--HH'/0"VHH'/0r#   )r   )r,   collections.abcr   r   typingr   r   r   cyclopts.utilsr   r(   ResultActionr   r"   r)    r#   r!   <module>r6      s    
 . % % & 	" ucz# * "H-?$@@s S  8ttt ud{#t 		tr#   