6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-11-15 17:47:13 +00:00
tutor/tutor/commands/cli.py

67 lines
1.7 KiB
Python
Raw Normal View History

#! /usr/bin/env python3
import sys
import appdirs
import click
import click_repl
from .android import android
2019-04-23 07:57:55 +00:00
from .config import config_command
from .context import Context
from .dev import dev
2019-04-23 07:57:55 +00:00
from .images import images_command
from .k8s import k8s
from .local import local
from .plugins import plugins_command, add_plugin_commands
from .ui import ui
from .webui import webui
from ..__about__ import __version__
from .. import exceptions
from .. import fmt
def main():
try:
click_repl.register_repl(cli, name="ui")
cli.add_command(images_command)
cli.add_command(config_command)
cli.add_command(local)
cli.add_command(dev)
cli.add_command(android)
cli.add_command(k8s)
cli.add_command(ui)
cli.add_command(webui)
cli.add_command(print_help)
cli.add_command(plugins_command)
add_plugin_commands(cli)
cli() # pylint: disable=no-value-for-parameter
except exceptions.TutorError as e:
2019-05-11 22:10:14 +00:00
fmt.echo_error("Error: {}".format(e.args[0]))
sys.exit(1)
2019-04-23 07:57:55 +00:00
@click.group(context_settings={"help_option_names": ["-h", "--help", "help"]})
@click.version_option(version=__version__)
@click.option(
"-r",
"--root",
envvar="TUTOR_ROOT",
default=appdirs.user_data_dir(appname="tutor"),
show_default=True,
type=click.Path(resolve_path=True),
help="Root project directory (environment variable: TUTOR_ROOT)",
)
@click.pass_context
def cli(context, root):
context.obj = Context(root)
2019-04-23 07:57:55 +00:00
@click.command(help="Print this help", name="help")
def print_help():
with click.Context(cli) as context:
click.echo(cli.get_help(context))
2019-04-23 07:57:55 +00:00
if __name__ == "__main__":
main()