U
    d	                     @   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              	      s^   t | tjstd pdD ]<}z| |  W q tk
rV   | t|j Y qX q| S )Nz<Plugins can only be attached to an instance of click.Group() )	
isinstanceclickGroup	TypeErrorZadd_commandload	ExceptionBrokenCommandname)groupZentry_pointpluginsr   6/tmp/pip-unpacked-wheel-w7ib5w2v/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   Z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
   Z
short_help)selfr
   Z	util_nameZ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   Z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	   )r)   r   r   r   r   r   r   r	   r   r   r   r   <module>   s   $