B
    ‹æ@\û  ã               @   sf   d Z ddlmZmZmZmZ ddlZe e¡Z	ddl
mZmZ ddlmZ dZG dd„ deeƒƒZdS )	zX Provides a base class for defining subcommands of the Bokeh command
line application.

é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)ÚABCMetaÚabstractmethod)Úwith_metaclass)Ú
Subcommandc               @   s$   e Zd ZdZdd„ Ze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', dict(
            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', dict(
                        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.

    c             C   sN   || _ t| ddƒ}x6|D ].}|d }t|tƒs4|f}| j j||d Ž qW 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``.

        Úargs© r   é   N)ÚparserÚgetattrÚ
isinstanceÚtupleÚadd_argument)Úselfr   r
   ÚargÚflagsr   r   ú7lib/python3.7/site-packages/bokeh/command/subcommand.pyÚ__init__b   s    

zSubcommand.__init__c             C   s   t dƒ‚dS )a   Takes over main program flow to perform the subcommand.

        *This method must be implemented by subclasses.*

        Args:
            args (seq) : command line arguments for the subcommand to parse

        Raises:
            NotImplementedError

        zimplement invoke()N)ÚNotImplementedError)r   r
   r   r   r   Úinvokev   s    zSubcommand.invokeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   0   s   0r	   )r   Z
__future__r   r   r   r   ZloggingZ	getLoggerr   ÚlogÚabcr   r   Zbokeh.util.futurer   Ú__all__r	   r   r   r   r   Ú<module>
   s   
