o
    h                     @   sj   d Z ddlmZ ddlZddlZddlZddlZdZdZ	dZ
dZdZd	d
 ZG dd dejZdd ZdS )zSee ``with_plugins()``.    entry_pointsNz2.0devzKevin Wurster, Sean Gilliesz*wursterk@gmail.com, sean.gillies@gmail.comz.https://github.com/click-contrib/click-pluginsa  
New BSD License

Copyright (c) 2015-2023, Kevin D. Wurster, Sean C. Gillies
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither click-plugins nor the names of its contributors may not be used to
  endorse or promote products derived from this software without specific prior
  written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
c                    s    fdd}|S )a  Decorator for loading plugins.

    Each entry point must point to a ``click.Command()`` object. An entry
    point producing an exception during loading will be wrapped in a
    ``BrokenCommand()``.

    Entry points can be loaded from multiple sources by decorating a command
    with multiple ``with_plugins()`` using different configurations.

    >>> from importlib.metadata import entry_points
    >>> import click
    >>> from click_plugins import with_plugins
    >>>
    >>> @with_plugins(entry_points(group='entry_point.name'))
    >>> @click.group()
    >>> def cli():
    ...     '''Commandline interface for something.'''
    >>>
    >>> @cli.command()
    >>> @click.argument('arg')
    >>> def subcommand(arg):
    ...     '''A subcommand for something else'''

    :param iterable or str entry_points:
        A string identifying a group of entry points to load or an iterable
        object producing ``importlib.metadata.EntryPoint()`` objects.

    :rtype click.Group:
    c                    s   t | tjstdt|  t  trt d}n }|D ]%}z	| |  W q t	yC } z| t
|| W Y d }~qd }~ww | S )NzDplugins can only be attached to an instance of 'click.Group()' not: )group)
isinstanceclickGroup	TypeErrorreprstrim_entry_pointsadd_commandload	ExceptionBrokenCommand)r   all_entry_pointseper    O/var/www/html/optinet_system/venv/lib/python3.10/site-packages/click_plugins.py	decoratorQ   s"   
zwith_plugins.<locals>.decoratorr   )r   r   r   r   r   with_plugins1   s    r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r   zRepresents a plugin ``click.Command()`` that failed to load.

    Can be executed just like a ``click.Command()``, but prints information
    for debugging and exits with an error code.
    c                    sJ   t  |j tj|}djt||jtj	d
| d| _d| _dS )z
        :param importlib.metadata.EntryPoint entry_point:
            Entry point that failed to load.
        :param Exception exception:
            Raised when attempting to load the entry point associated with
            this instance.
        zf{ls}ERROR: entry point '{module}:{name}' could not be loaded. Contact its author for help.{ls}{ls}{tb} )modulenamelstbuO   † Warning: could not load plugin. Invoke command with '--help' for traceback.N)super__init__r   	tracebackTracebackExceptionfrom_exceptionformat_moduleoslinesepjoinhelp
short_help)selfentry_point	exceptiontbe	__class__r   r   r   x   s   
zBrokenCommand.__init__c                 C   s"   t j| j|jdd |d dS )znPrint traceback and debugging message.

        :param click.Context ctx:
            Active context.
        T)colorerr   N)r   echor&   r.   exit)r(   ctxr   r   r   invoke   s   zBrokenCommand.invokec                 C   s   |S )zPass arguments along without parsing.

        :param click.Context ctx:
            Active context.
        :param list args:
            List of command line arguments.
        r   )r(   r3   argsr   r   r   
parse_args   s   zBrokenCommand.parse_args)__name__
__module____qualname____doc__r   r4   r6   __classcell__r   r   r,   r   r   p   s
    )r   c                 C   s0   t jdkr
| j}|S | j| j}|d}|S )zModule name for a given entry point.

    Parameters
    ----------
    ep : importlib.metadata.EntryPoint
        Determine parent module for this entry point.

    Returns
    -------
    str
    )   
   r   )sysversion_infor   patternmatchvaluer   )r   r   rA   r   r   r   r"      s   

r"   )r:   importlib.metadatar   r   r#   r>   r   r   __version__
__author__	__email__
__source____license__r   Commandr   r"   r   r   r   r   <module>   s    !?O