#AUTOGENERATED! DO NOT EDIT! File to edit: dev/05_cli.ipynb (unless otherwise specified).

__all__ = ['ClickLiteralOption']

#Cell
from ast import literal_eval
import click
from functools import partial

#Cell
class ClickLiteralOption(click.Option):
    """Command line option that lets user input Python data structures
    which aren't offered by Click.

    Examples
    --------
    # Notice that the input structure must be enclosed in quotes.

    @click.command(help='Sample command.')
    @click.option('--lr', cls=ClickLiteralOption, default="[3e-3, 3e-4, 1e-5]")
    def train(lr):
        # Code to train model.
    """

    def type_cast_value(self, ctx, val):
        try:
            return literal_eval(val)
        except:
            raise click.BadParameter('Failed to parse arg as Python literal.')

#Cell
click.command = partial(
    click.command,
    context_settings={'help_option_names': ['--help', '-h']}
)
click.option = partial(click.option, show_default=True)