-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
33 lines (26 loc) · 1.04 KB
/
cli.py
File metadata and controls
33 lines (26 loc) · 1.04 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
from microcli.ex_parser import parse_input
from microcli.ex_handler import *
def main():
print("MicroCLI is ready. Type a command or 'exit' to quit.")
while True:
raw_input_str = input("microcli > ").strip()
if raw_input_str.lower() in ["exit", "quit"]:
print("Exiting MicroCLI...")
break
try:
command_name, parsed_flags, meta = parse_input(raw_input_str)
print("✅ Command is valid.")
print("🔹 Tokens:", [command_name] + [f"{k}={v}" for k, v in parsed_flags.items()])
print("🔹 Metadata:", meta)
# Dynamically call the handler
handler_name = meta["handler"]
handler_func = globals().get(handler_name)
if handler_func:
result = handler_func(**parsed_flags)
print(result)
else:
print(f"❌ Handler not found for command: {command_name}")
except ValueError as e:
print("❌ Error:", e)
if __name__ == "__main__":
main()