crhelp 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.
- crhelp/__init__.py +6 -0
- crhelp/cli.py +85 -0
- crhelp/data/allcodes.txt +1633 -0
- crhelp/data/turtlecode.txt +164 -0
- crhelp-1.0.0.dist-info/METADATA +45 -0
- crhelp-1.0.0.dist-info/RECORD +10 -0
- crhelp-1.0.0.dist-info/WHEEL +5 -0
- crhelp-1.0.0.dist-info/entry_points.txt +2 -0
- crhelp-1.0.0.dist-info/licenses/LICENSE +21 -0
- crhelp-1.0.0.dist-info/top_level.txt +1 -0
crhelp/__init__.py
ADDED
crhelp/cli.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Command-line interface for crhelp.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
crhelp list List available code files.
|
|
5
|
+
crhelp show <name> Display contents of a code file.
|
|
6
|
+
crhelp --version Print version.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from crhelp import __version__
|
|
14
|
+
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
# Resolve the data directory bundled inside the installed package.
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
_DATA_DIR = Path(__file__).resolve().parent / "data"
|
|
19
|
+
|
|
20
|
+
# Only the two original files are exposed.
|
|
21
|
+
_AVAILABLE_FILES = {
|
|
22
|
+
"allcodes": _DATA_DIR / "allcodes.txt",
|
|
23
|
+
"turtlecode": _DATA_DIR / "turtlecode.txt",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _cmd_list(args):
|
|
28
|
+
"""Print the names of all available code files."""
|
|
29
|
+
print("Available files:")
|
|
30
|
+
for name in sorted(_AVAILABLE_FILES):
|
|
31
|
+
print(f" {name}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _cmd_show(args):
|
|
35
|
+
"""Print the full contents of the requested file to stdout."""
|
|
36
|
+
name = args.name
|
|
37
|
+
if name not in _AVAILABLE_FILES:
|
|
38
|
+
print(f"Error: '{name}' is not a valid file name.", file=sys.stderr)
|
|
39
|
+
print(f"Run 'crhelp list' to see available files.", file=sys.stderr)
|
|
40
|
+
sys.exit(1)
|
|
41
|
+
|
|
42
|
+
filepath = _AVAILABLE_FILES[name]
|
|
43
|
+
if not filepath.exists():
|
|
44
|
+
print(f"Error: data file '{filepath}' not found.", file=sys.stderr)
|
|
45
|
+
sys.exit(1)
|
|
46
|
+
|
|
47
|
+
print(filepath.read_text(encoding="utf-8"))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def main():
|
|
51
|
+
parser = argparse.ArgumentParser(
|
|
52
|
+
prog="crhelp",
|
|
53
|
+
description="Cognitive Robotics Helper - view lab code snippets.",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--version",
|
|
57
|
+
action="version",
|
|
58
|
+
version=f"%(prog)s {__version__}",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
62
|
+
|
|
63
|
+
# --- crhelp list ---
|
|
64
|
+
subparsers.add_parser("list", help="List available code files.")
|
|
65
|
+
|
|
66
|
+
# --- crhelp show <name> ---
|
|
67
|
+
show_parser = subparsers.add_parser("show", help="Display a code file.")
|
|
68
|
+
show_parser.add_argument(
|
|
69
|
+
"name",
|
|
70
|
+
help="Name of the file to display (e.g. allcodes, turtlecode).",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
args = parser.parse_args()
|
|
74
|
+
|
|
75
|
+
if args.command == "list":
|
|
76
|
+
_cmd_list(args)
|
|
77
|
+
elif args.command == "show":
|
|
78
|
+
_cmd_show(args)
|
|
79
|
+
else:
|
|
80
|
+
parser.print_help()
|
|
81
|
+
sys.exit(0)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
main()
|