-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (72 loc) · 2.03 KB
/
main.py
File metadata and controls
86 lines (72 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import click
from app.commands.adminapi import AdminAPICommand
from app.commands.dataapi import DataAPICommand
from app.commands.generate_spec import GenerateSpecCommand
from app.commands.runtask import RunTaskCommand
from app.lib import commands
@click.group()
@click.option(
"--log-level",
type=click.Choice(["debug", "info", "warning", "error", "critical"], case_sensitive=False),
default="info",
help="Set the logging level (for runtask and other commands that use it)",
)
@click.pass_context
def cli(ctx: click.Context, log_level: str) -> None:
ctx.ensure_object(dict)
ctx.obj["log_level"] = log_level
@cli.command(short_help=AdminAPICommand.help())
@click.option(
"-c",
"--config",
type=str,
default=lambda: os.environ.get("CONFIG", ""),
help="Path to configuration file",
)
def adminapi(config: str):
commands.run(AdminAPICommand(config))
@cli.command(short_help=DataAPICommand.help())
@click.option(
"-c",
"--config",
type=str,
default=lambda: os.environ.get("CONFIG", ""),
help="Path to configuration file",
)
def dataapi(config: str):
commands.run(DataAPICommand(config))
@cli.command(short_help=RunTaskCommand.help(), context_settings={"ignore_unknown_options": True})
@click.argument(
"task_name",
required=True,
type=str,
)
@click.option(
"-i",
"--input-data",
type=str,
help="Path to input data file",
)
@click.pass_context
@click.argument("task_args", nargs=-1, type=click.UNPROCESSED)
def runtask(
ctx: click.Context,
task_name: str,
input_data: str | None,
task_args: tuple[str, ...],
) -> None:
log_level = (ctx.obj or {}).get("log_level", "info")
commands.run(RunTaskCommand(task_name, input_data, None, task_args, log_level))
@cli.command(short_help=GenerateSpecCommand.help())
@click.option(
"-o",
"--output",
type=str,
required=True,
help="Where to put resulting JSON",
)
def generate_spec(output: str):
commands.run(GenerateSpecCommand(output))
if __name__ == "__main__":
cli()