generated from softwareone-platform/swo-extension-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
85 lines (73 loc) · 2.81 KB
/
cli.py
File metadata and controls
85 lines (73 loc) · 2.81 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
import logging
from typing import Annotated
import typer
from mpt_tool.commands import CommandFactory, MigrateCommandValidator
from mpt_tool.commands.errors import BadParameterError, CommandNotFoundError
from mpt_tool.use_cases.errors import UseCaseError
app = typer.Typer(help="MPT CLI - Migration tool for extensions.", no_args_is_help=True)
@app.callback()
def callback() -> None:
"""MPT CLI - Migration tool for extensions."""
@app.command("migrate")
def migrate( # noqa: WPS211
ctx: typer.Context,
check: Annotated[ # noqa: FBT002
bool, typer.Option("--check", help="Check for duplicate migration_id in migrations.")
] = False,
data: Annotated[bool, typer.Option("--data", help="Run data migrations.")] = False, # noqa: FBT002
schema: Annotated[bool, typer.Option("--schema", help="Run schema migrations.")] = False, # noqa: FBT002
manual: Annotated[
str | None,
typer.Option(
"--manual",
help="Mark the migration provided as applied without running it",
metavar="MIGRATION_ID",
),
] = None,
init: Annotated[ # noqa: FBT002
bool, typer.Option("--init", help="Initialize migration tool resources.")
] = False,
new_data: Annotated[
str | None,
typer.Option(
"--new-data",
metavar="FILENAME",
help="Scaffold a new data migration script with the provided filename.",
),
] = None,
new_schema: Annotated[
str | None,
typer.Option(
"--new-schema",
metavar="FILENAME",
help="Scaffold a new schema migration script with the provided filename.",
),
] = None,
list: Annotated[bool, typer.Option("--list", help="List all migrations.")] = False, # noqa: A002, FBT002
migration_id: Annotated[
str | None, typer.Argument(help="Optional migration ID for --data or --schema.")
] = None,
) -> None:
"""Migrate command."""
try:
MigrateCommandValidator.validate(ctx.params)
except BadParameterError as error:
raise typer.BadParameter(str(error), param_hint="migrate")
try:
command_instance = CommandFactory.get_instance(ctx.params)
except CommandNotFoundError:
raise typer.BadParameter("No valid param provided.", param_hint="migrate")
typer.echo(command_instance.start_message)
try:
command_instance.run()
except UseCaseError as error:
typer.secho(
f"Error running {command_instance.name} command: {error!s}",
fg=typer.colors.RED,
)
raise typer.Abort
typer.secho(command_instance.success_message, fg=typer.colors.GREEN)
def main() -> None:
"""Entry point for the CLI."""
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
app()