-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_explainer.py
More file actions
39 lines (32 loc) · 1.09 KB
/
Copy pathcmd_explainer.py
File metadata and controls
39 lines (32 loc) · 1.09 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
#!/usr/bin/env python3
"""Minimal entrypoint for cmd-explainer.
This provides two modes:
- Interactive REPL (no args)
- Single command mode: pass a command string as an argument
The implementation intentionally keeps the feature set small so the
repository is runnable without the larger datasets mentioned in the
original README (man DB, index files, etc.).
"""
import argparse
import sys
from src import parser as _parser
from src import visualizer as _viz
def main():
ap = argparse.ArgumentParser(prog="cmd_explainer")
ap.add_argument("command", nargs="*", help="Command to explain (if omitted, enter interactive mode)")
args = ap.parse_args()
if not args.command:
# interactive
try:
from src.shell import interactive_shell
except Exception as e:
print("Interactive shell dependencies are missing:", e)
sys.exit(1)
interactive_shell()
else:
cmd = " ".join(args.command)
structure = _parser.parse_command(cmd)
out = _viz.render(structure)
print(out)
if __name__ == "__main__":
main()