import click

from wurker.__about__ import __version__
from wurker.util import init_logger

# We put the click functions in each command's module
from .commands.admin import admin
from .commands.show import register_show_command
from .commands.add import register_add_command
from .commands.edit import register_edit_command
from .commands.remove import register_remove_command
from .commands.run import register_run_command
from .commands.kill import register_kill_command
from .commands.report import register_report_command


# The top-level 'wurk' group context gets passed down the command tree
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
@click.version_option(version=__version__, prog_name="wurk")
@click.option(
    "--log", default='syslog', type=click.Choice(['stderr','syslog']), help="Where to log (default: 'syslog')"
)
@click.option("--debug", is_flag=True, help="Override configured debug mode?")
@click.pass_context
def wurk(ctx, log, debug):
    """Wurker CLI - manage resources, definitions, and bees"""

    ctx.ensure_object(dict)

    from wurker.settings import conf
    debug = debug or conf.debug

    logger = init_logger(log=log, debug=debug)
    ctx.obj['logger'] = logger


# Add the top-level command groups
wurk.add_command(admin)
register_show_command(wurk)
register_add_command(wurk)
register_edit_command(wurk)
register_remove_command(wurk)
register_run_command(wurk)
register_kill_command(wurk)
register_report_command(wurk)
