Repository navigation
Expand file tree
/
Copy pathdevelop.py
More file actions
76 lines (63 loc) · 1.77 KB
/
Copy pathdevelop.py
File metadata and controls
76 lines (63 loc) · 1.77 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
import argparse
import shlex
import subprocess
from dataclasses import dataclass
@dataclass
class Command:
alias: str
help_text: str
commands_list: list[str]
COMMANDS = [
Command(
alias="start-db",
help_text="Start the database",
commands_list=[
"docker compose up -d wf_postgres_service",
],
),
Command(
alias="stop-db",
help_text="Stop the database",
commands_list=[
"docker compose stop wf_postgres_service",
],
),
Command(
alias="reset-db",
help_text="Reset the database",
commands_list=[
"python manage.py reset_db --noinput -c",
"python manage.py migrate",
],
),
Command(
alias="scaffold-db",
help_text="Scaffold initial database content",
commands_list=[
"python manage.py scaffold_initial_content",
],
),
Command(
alias="test",
help_text="Run tests",
commands_list=[
"python manage.py test",
],
),
]
def run_command(command: str) -> None:
subprocess.run(shlex.split(command), check=True) # noqa: S603 - commands are the fixed COMMANDS above
def run_commands(commands: list[str]) -> None:
for command in commands:
run_command(command)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Development tasks.")
subparsers = parser.add_subparsers()
for command in COMMANDS:
subparser = subparsers.add_parser(command.alias, help=command.help_text)
subparser.set_defaults(commands_list=command.commands_list)
args = parser.parse_args()
if "commands_list" in args:
run_commands(args.commands_list)
else:
parser.print_help()