o
    i                  	   @   s  d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZ d dlmZ ejdk r6d dlmZ nd dlmZ erDd dlma ed	Zda		
ddede jdB de
d fddZedededdef f de
d defddZededef de
d defddZedddededde	f f dedB de	fddZedddede	f dedB de	fddZdddedB fddZdS )    N)Callable	Coroutine)partial)TYPE_CHECKINGAnyLiteralTypeVaroverload)ResultAction)      )assert_neverAppVasynciocommandboundbackend)r   trioc                 C   s   t | s|du r|  S | |ji |jS |dkr3ddl}|du r'||  S || |ji |jS |dkrTddl}|du rD|| S |t| g|jR i |jS t| dS )a  Run a command, handling both sync and async cases.

    If the command is async, an async context will be created to run it.

    Parameters
    ----------
    command : Callable
        The command to execute.
    bound : inspect.BoundArguments | None
        Bound arguments for the command. If None, command is called with no arguments.
    backend : Literal["asyncio", "trio"]
        The async backend to use if the command is async.

    Returns
    -------
    return_value: Any
        The value the command function returns.
    Nr   r   r   )	inspectiscoroutinefunctionargskwargsr   runr   r   r   )r   r   r   r   r    r   S/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/_run.py_run_maybe_async_command   s   

 r   callable.result_actionreturn_valuereturnc               C      d S Nr   r   r   r   r   r   r   F      r   c               C   r"   r#   r   r$   r   r   r   r   J   r%   r   c               C   r"   r#   r   r$   r   r   r   r   N   s   c               C   r"   r#   r   r$   r   r   r   r   T   r%   c               C   s2   t du rddlm } |a t |d}||  | S )a  Run the given callable as a CLI command.

    The callable may also be a coroutine function.
    This function is syntax sugar for very simple use cases, and is roughly equivalent to:

    .. code-block:: python

        from cyclopts import App

        app = App()
        app.default(callable)
        app()

    Parameters
    ----------
    callable
        The function to execute as a CLI command.
    result_action
        How to handle the command's return value. If not specified, uses the default
        ``"print_non_int_sys_exit"`` which calls :func:`sys.exit` with the appropriate code.
        Can be set to ``"return_value"`` to return the result directly for testing/embedding.

    Example usage:

    .. code-block:: python

        import cyclopts


        def main(name: str, age: int):
            print(f"Hello {name}, you are {age} years old.")


        cyclopts.run(main)
    Nr   r   r&   )r   cyclopts.coredefault)r   r   _Appappr   r   r   r   X   s   %

)Nr   )r   syscollections.abcr   r   	functoolsr   typingr   r   r   r   r	   cyclopts._result_actionr
   version_infotyping_extensionsr   r'   r   r   BoundArgumentsr   r   r   r   r   r   <module>   sL    

/.$*