U
    /e                     @  s   d Z ddlmZ ddlZeeZddlmZm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZ d
ZeG dd dZeeeeedf f ef Zeedf ZG dd dedZ dS )zX Provides a base class for defining subcommands of the Bokeh command
line application.

    )annotationsN)ABCMetaabstractmethod)ArgumentParser	Namespace)AnyClassVarSequenceTupleTypeUnion)Literal   )NotRequiredUnspecified	dataclassentries)
Subcommandc                   @  sz   e Zd ZU eZded< eZded< eZded< eZded< eZ	ded	< eZ
d
ed< eZded< eZded< eZded< dS )Argumentz|NotRequired[Literal[('store', 'store_const', 'store_true', 'append', 'append_const', 'count', 'help', 'version', 'extend')]]actionz8NotRequired[Union[int, Literal[('?', '*', '+', '...')]]]nargszNotRequired[Any]constdefaultzNotRequired[Type[Any]]typezNotRequired[Sequence[Any]]choiceszNotRequired[bool]requiredzNotRequired[str]helpmetavarN)__name__
__module____qualname__r   r   __annotations__r   r   r   r   r   r   r   r    r"   r"   </tmp/pip-unpacked-wheel-f5fndrjf/bokeh/command/subcommand.pyr   ?   s   
r   .c                   @  sR   e Zd ZU dZded< ded< dZded< dd	d
ddZedddddZdS )r   a   Abstract base class for subcommands

    Subclasses should implement an ``invoke(self, args)`` method that accepts
    a set of argparse processed arguments as input.

    Subclasses should also define the following class attributes:

    * ``name`` a name for this subcommand

    * ``help`` a help string for argparse to use for this subcommand

    * ``args`` the parameters to pass to ``parser.add_argument``

    The format of the ``args`` should be a sequence of tuples of the form:

    .. code-block:: python

        ('argname', Argument(
            metavar='ARGNAME',
            nargs='+',
        ))

    Example:

        A simple subcommand "foo" might look like this:

        .. code-block:: python

            class Foo(Subcommand):

                name = "foo"
                help = "performs the Foo action"
                args = (
                    ('--yell', Argument(
                        action='store_true',
                        help="Make it loud",
                    )),
                )

                def invoke(self, args):
                    if args.yell:
                        print("FOO!")
                    else:
                        print("foo")

        Then executing ``bokeh foo --yell`` would print ``FOO!`` at the console.

    zClassVar[str]namer   r"   zClassVar[Args]argsr   None)parserreturnc                 C  sX   || _ | jD ]F}|\}}t|ts(|f}t|ts@tt|}n|}| j j|| qdS )at   Initialize the subcommand with its parser

        Args:
            parser (Parser) : an Argparse ``Parser`` instance to configure
                with the args for this subcommand.

        This method will automatically add all the arguments described in
        ``self.args``. Subclasses can perform any additional customizations
        on ``self.parser``.

        N)r'   r%   
isinstancetupledictr   add_argument)selfr'   argflagsspeckwargsr"   r"   r#   __init__   s    


zSubcommand.__init__r   zUnion[bool, None])r%   r(   c                 C  s   t ddS )a   Takes over main program flow to perform the subcommand.

        *This method must be implemented by subclasses.*
        subclassed overwritten methods return different types:
        bool: Build
        None: FileOutput (subclassed by HTML, SVG and JSON. PNG overwrites FileOutput.invoke method), Info, Init,                 Sampledata, Secret, Serve, Static


        Args:
            args (argparse.Namespace) : command line arguments for the subcommand to parse

        Raises:
            NotImplementedError

        zimplement invoke()N)NotImplementedError)r-   r%   r"   r"   r#   invoke   s    zSubcommand.invokeN)	r   r   r    __doc__r!   r%   r2   r   r4   r"   r"   r"   r#   r   N   s   
1r   )	metaclass)!r5   
__future__r   logging	getLoggerr   logabcr   r   argparser   r   typingr   r   r	   r
   r   r   Ztyping_extensionsr   Zutil.dataclassesr   r   r   r   __all__r   strZArgZArgsr   r"   r"   r"   r#   <module>   s   
 
