feat: clearer Arguments editor with typed-together detection and one-click fix
- Label now explains the model with an example: a flag and its value go
on separate lines. Placeholder shows the common uv pattern.
- split_suspicious_args() flags lines that contain whitespace plus a
dash-prefixed token ('--directory /path') — legit single args with
spaces ('My Documents') are never touched. Quotes are respected.
- The editor shows a warning under the args box with a 'Fix: split onto
separate lines' button; the fix goes through the undo stack.
This commit is contained in:
+36
@@ -580,6 +580,42 @@ def parse_pasted_json(text: str) -> dict[str, dict]:
|
||||
return servers
|
||||
|
||||
|
||||
def split_suspicious_args(args: list[str]) -> tuple[list[str], list[str]]:
|
||||
"""
|
||||
Detect the classic argument-entry mistake: several argv tokens typed on one
|
||||
line ("--directory /path/to/server"). An entry is only flagged when it
|
||||
contains whitespace AND at least one whitespace-separated token starts with
|
||||
"-" — so legitimate single arguments with spaces ("My Project Notes",
|
||||
"/Users/me/My Documents") are never touched.
|
||||
|
||||
Returns (fixed_args, notes). notes is empty when nothing was suspicious;
|
||||
otherwise it describes each split so a UI can show the proposed fix.
|
||||
Quotes are respected when splitting ('--name "My Server"' becomes
|
||||
['--name', 'My Server']).
|
||||
"""
|
||||
import shlex
|
||||
|
||||
out: list[str] = []
|
||||
notes: list[str] = []
|
||||
for a in args:
|
||||
if isinstance(a, str) and _looks_like_multiple_args(a):
|
||||
try:
|
||||
parts = shlex.split(a)
|
||||
except ValueError: # unbalanced quotes — fall back to plain split
|
||||
parts = a.split()
|
||||
if len(parts) > 1:
|
||||
out.extend(parts)
|
||||
notes.append(f"“{a}” looks like {len(parts)} arguments — split onto separate lines")
|
||||
continue
|
||||
out.append(a)
|
||||
return out, notes
|
||||
|
||||
|
||||
def _looks_like_multiple_args(a: str) -> bool:
|
||||
toks = a.split()
|
||||
return len(toks) > 1 and any(t.startswith("-") for t in toks)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Validation
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user