-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
25 lines (20 loc) · 770 Bytes
/
parser.py
File metadata and controls
25 lines (20 loc) · 770 Bytes
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
import shlex
from typing import List
class CommandParser:
@staticmethod
def parse(raw_input: str) -> List[str]:
"""
Tokenizes raw string input into a list of arguments.
Handles multi-word quoted strings and returns specific errors on failure.
"""
if not raw_input or not raw_input.strip():
return []
try:
tokens = shlex.split(raw_input)
if tokens:
tokens[0] = tokens[0].upper()
return tokens
except ValueError as e:
# Instead of silently returning [], we capture the exact shlex error
# (e.g., "No closing quotation") and pass it downstream.
return ["ERROR", f"ERR parsing command: {str(e).lower()}"]