2019-01-22 20:25:04 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
|
2019-12-12 16:05:56 +00:00
|
|
|
import appdirs
|
2019-01-22 20:25:04 +00:00
|
|
|
import click
|
|
|
|
import click_repl
|
|
|
|
|
|
|
|
from .android import android
|
2019-04-23 07:57:55 +00:00
|
|
|
from .config import config_command
|
2020-01-08 18:38:13 +00:00
|
|
|
from .context import Context
|
2019-01-22 20:25:04 +00:00
|
|
|
from .dev import dev
|
2019-04-23 07:57:55 +00:00
|
|
|
from .images import images_command
|
2019-01-22 20:25:04 +00:00
|
|
|
from .k8s import k8s
|
|
|
|
from .local import local
|
2019-12-12 16:23:46 +00:00
|
|
|
from .plugins import plugins_command, add_plugin_commands
|
2019-01-22 20:25:04 +00:00
|
|
|
from .ui import ui
|
|
|
|
from .webui import webui
|
2019-05-11 19:20:09 +00:00
|
|
|
from ..__about__ import __version__
|
|
|
|
from .. import exceptions
|
|
|
|
from .. import fmt
|
2019-01-22 20:25:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
2020-01-14 14:42:20 +00:00
|
|
|
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)
|
2019-12-12 16:05:56 +00:00
|
|
|
cli() # pylint: disable=no-value-for-parameter
|
2019-01-22 20:25:04 +00:00
|
|
|
except exceptions.TutorError as e:
|
2019-05-11 22:10:14 +00:00
|
|
|
fmt.echo_error("Error: {}".format(e.args[0]))
|
2019-01-22 20:25:04 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
@click.group(context_settings={"help_option_names": ["-h", "--help", "help"]})
|
Fix version information in bundle
`./dist/tutor --version` raises an error:
Traceback (most recent call last):
File "main", line 4, in <module>
File "tutor/cli.py", line 21, in main
File "click/core.py", line 764, in __call__
File "click/core.py", line 716, in main
File "click/core.py", line 641, in make_context
File "click/core.py", line 1089, in parse_args
File "click/core.py", line 940, in parse_args
File "click/core.py", line 1477, in handle_parse_result
File "click/core.py", line 96, in invoke_param_callback
File "click/decorators.py", line 270, in callback
RuntimeError: Could not determine version
[1659] Failed to execute script main
To address this, we pass the version value directly to click.
This is for issue #156.
2019-02-10 17:31:48 +00:00
|
|
|
@click.version_option(version=__version__)
|
2019-12-12 16:05:56 +00:00
|
|
|
@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-01-22 20:25:04 +00:00
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
@click.command(help="Print this help", name="help")
|
2019-01-22 20:25:04 +00:00
|
|
|
def print_help():
|
|
|
|
with click.Context(cli) as context:
|
|
|
|
click.echo(cli.get_help(context))
|
|
|
|
|
2019-04-23 07:57:55 +00:00
|
|
|
|
2019-01-22 20:25:04 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|