work on v0.3.0

This commit is contained in:
2025-02-17 20:57:15 +03:00
parent 37b62fd69b
commit a9e545f3d8
20 changed files with 47 additions and 77 deletions
+5 -52
View File
@@ -1,53 +1,6 @@
import re
from pprint import pprint
from typing import Literal, LiteralString
class CommandParseError(Exception):
pass
def parse_command(command: str) -> dict:
pattern = re.compile(r"""
(?P<command>^\S+)
|
(?P<arg_prefix>-{1,3})(?P<arg>\w+)
|
(?P<value>\S+)
""", re.VERBOSE)
tokens = pattern.findall(command)
if not tokens:
raise CommandParseError("Invalid command format")
result = {}
args = {}
current_arg = None
for token in tokens:
command_name, arg_prefix, arg_name, value = token
if command_name:
if "command" in result:
raise CommandParseError("Multiple command names found")
result["command"] = command_name
elif arg_name:
if current_arg:
raise CommandParseError(f"Argument {current_arg} has no value")
current_arg = f"{arg_prefix}{arg_name}"
elif value:
if not current_arg:
raise CommandParseError(f"Unexpected value: {value}")
args[current_arg] = value
current_arg = None
if current_arg:
raise CommandParseError(f"Argument {current_arg} has no value")
result["args"] = args
return result
command_str = "run"
parsed = (command_str)
pprint(parsed)
x: LiteralString = '---'
m: LiteralString = input()
if m == '-':
x = m