o
    Df	                     @   sB   d Z ddlZddlZddlZddlZdd ZG dd dejZdS )z#
Core components for click_plugins
    Nc                    s    fdd}|S )ap  
    A decorator to register external CLI commands to an instance of
    `click.Group()`.

    Parameters
    ----------
    plugins : iter
        An iterable producing one `pkg_resources.EntryPoint()` per iteration.
    attrs : **kwargs, optional
        Additional keyword arguments for instantiating `click.Group()`.

    Returns
    -------
    click.Group()
    c              	      sZ   t | tjs
td pdD ]}z	| |  W q ty*   | t|j Y qw | S )Nz<Plugins can only be attached to an instance of click.Group() )	
isinstanceclickGroup	TypeErroradd_commandload	ExceptionBrokenCommandname)groupentry_pointpluginsr   K/home/ubuntu/webapp/venv/lib/python3.10/site-packages/click_plugins/core.py	decorator   s   zwith_plugins.<locals>.decoratorr   )r   r   r   r   r   with_plugins   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r
   a^  
    Rather than completely crash the CLI when a broken plugin is loaded, this
    class provides a modified help message informing the user that the plugin is
    broken and they should contact the owner.  If the user executes the plugin
    or specifies `--help` a traceback is reported showing the exception the
    plugin loader encountered.
    c                 C   sf   t j| | tjtjrtjd pt}tj	
drd}nd}dt  | _|d|| jf  | _dS )z[
        Define the special help messages after instantiating a `click.Command()`.
        r   CLICK_PLUGINS_HONESTLYu   💩u   †zK
Warning: entry point could not be loaded. Contact its author for help.


z4 Warning: could not load plugin. See `%s %s --help`.N)r   Command__init__ospathbasenamesysargv__file__environget	traceback
format_exchelpr   
short_help)selfr   	util_nameiconr   r   r   r   ;   s   zBrokenCommand.__init__c                 C   s    t j| j|jd |d dS )z?
        Print the traceback instead of doing nothing.
        )color   N)r   echor    r%   exit)r"   ctxr   r   r   invokeR   s   zBrokenCommand.invokec                 C   s   |S )Nr   )r"   r)   argsr   r   r   
parse_args[   s   zBrokenCommand.parse_argsN)__name__
__module____qualname____doc__r   r*   r,   r   r   r   r   r
   1   s
    	r
   )r0   r   r   r   r   r   r   r
   r   r   r   r   <module>   s    $