o
    Œ¨Êh«	  ã                   @   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   úD/var/www/html/env/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    $