Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
80 lines (73 loc) · 2.98 KB
/
Copy pathcli.py
File metadata and controls
80 lines (73 loc) · 2.98 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
from pathlib import Path
import argparse
from pypp_cli.delete_cpp_libs.node import pypp_delete_cpp_libs
from pypp_cli.do.node import pypp_do
from pypp_cli.init.node import pypp_init
from pypp_cli.delete_timestamps.node import pypp_delete_timestamps
from pypp_cli.delete_cpp.node import pypp_delete_cpp
def main_cli(absolute_dir: Path | None = None) -> None:
parser = argparse.ArgumentParser(description="The Py++ CLI tool.")
subparsers = parser.add_subparsers(dest="mode", required=False)
subparsers.add_parser(
"init", help="Initialize a new Py++ project in the current directory."
)
subparsers.add_parser(
"delete_timestamps",
help="Delete the file_timestamps.json file so that the next transpile is done "
"for all python files regardless of whether they were modified.",
)
subparsers.add_parser(
"delete_cpp",
help="Delete everything in the C++ directory so that all C++ code is "
"regenerated. This also deletes the file_timestamps.json file and sets "
"cpp_dir_is_dirty to true in proj_info.json.",
)
subparsers.add_parser(
"delete_cpp_libs",
help="Delete everything in the C++ libs directory so that the C++ code from "
"libraries is recopied into it on the next transpile. This also deletes the "
"file_timestamps.json file.",
)
parser_do = subparsers.add_parser(
"do", help="transpile, format, build, and/or run."
)
parser_do.add_argument(
"tasks",
help="Transpile your Py++ code to C++, format the generated C++ code, build "
"the C++ code, and/or run the resulting executable. You can choose one or "
"multiple, and in any order (though, not every order makes sense)."
"For example, 'transpile format build' will transpile, format, and build ",
choices=["transpile", "format", "build", "run"],
nargs="+",
)
parser_do.add_argument(
"--exe_name",
"-e",
help="The name of the executable to run "
"(required if 'run' is one of the tasks).",
required=False,
)
args = parser.parse_args()
if absolute_dir is None:
absolute_dir = Path.cwd()
if args.mode == "init":
pypp_init(absolute_dir)
elif not (absolute_dir / ".pypp" / "proj_info.json").exists():
parser.error(
".pypp/proj_info.json file not found. "
"Ensure your Py++ project is properly initialized."
)
if args.mode == "do":
if "run" in args.tasks and not args.exe_name:
parser.error(
"argument --exe_name/-e is required when 'run' is one of the tasks."
)
pypp_do(args.tasks, absolute_dir, args.exe_name)
elif args.mode == "delete_timestamps":
pypp_delete_timestamps(absolute_dir)
elif args.mode == "delete_cpp":
pypp_delete_cpp(absolute_dir)
elif args.mode == "delete_cpp_libs":
pypp_delete_cpp_libs(absolute_dir)
if __name__ == "__main__":
main_cli()