typescratch 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
typescratch/cli.py ADDED
@@ -0,0 +1,67 @@
1
+ """CLI entry point for TypeScratch.
2
+
3
+ Usage:
4
+ typescratch build <file.tysh> [--out <out.sb3>] [--debug]
5
+ typescratch run <file.tysh> [--debug] # alias for build
6
+ typescratch version
7
+ typescratch help
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import sys
14
+ from typing import List
15
+
16
+ from . import __version__, file as _file
17
+ from .errors import CompileError
18
+
19
+
20
+ def main(argv: List[str] = None) -> int:
21
+ parser = argparse.ArgumentParser(
22
+ prog="typescratch",
23
+ description="Compile .tysh source files to Scratch 3 (.sb3) files.",
24
+ )
25
+ sub = parser.add_subparsers(dest="cmd", required=True)
26
+
27
+ p_build = sub.add_parser("build", help="Compile a .tysh file to .sb3")
28
+ p_build.add_argument("source", help="path to .tysh source file")
29
+ p_build.add_argument("--out", "-o", default=None, help="output .sb3 path")
30
+ p_build.add_argument("--debug", action="store_true", help="verbose debug output")
31
+
32
+ p_run = sub.add_parser("run", help="Alias for build")
33
+ p_run.add_argument("source")
34
+ p_run.add_argument("--out", "-o", default=None)
35
+ p_run.add_argument("--debug", action="store_true")
36
+
37
+ sub.add_parser("version", help="Print version")
38
+
39
+ args = parser.parse_args(argv)
40
+
41
+ if args.cmd == "version":
42
+ print(f"TypeScratch v{__version__}")
43
+ return 0
44
+
45
+ if args.cmd in ("build", "run"):
46
+ try:
47
+ out_path = _file(args.source, out=args.out, debug=args.debug)
48
+ print(f"OK: wrote {out_path}", file=sys.stderr)
49
+ return 0
50
+ except CompileError as e:
51
+ print(f"error: {e}", file=sys.stderr)
52
+ return 1
53
+ except FileNotFoundError as e:
54
+ print(f"error: {e}", file=sys.stderr)
55
+ return 2
56
+ except Exception as e:
57
+ print(f"internal error: {e}", file=sys.stderr)
58
+ import traceback
59
+ traceback.print_exc(file=sys.stderr)
60
+ return 3
61
+
62
+ parser.print_help()
63
+ return 1
64
+
65
+
66
+ if __name__ == "__main__":
67
+ sys.exit(main())