fix: preserve whitespace in positional arguments - #2423
Conversation
|
@lenamonj can you give the usage example of the real CLI interface that you are trying to fix? Shell doesn't allow me to enter tab into CLI, needless to say it won't split it. |
|
@abitrolly It works by quoting the input I personally use this for curl, for example when providing some ad-hoc JSON |
|
Sure - quoting is how the whitespace gets in, as @avorima says. The case Before this change the action receives "notes.txt" with the space stripped, so the open fails with a confusing "no such file" for a file that plainly exists. Same shape for any argument where whitespace is content rather than separator - a search pattern of two spaces, or a message string built by a The parser is right to trim when classifying the token (deciding flag vs |
parseFlagscomputesfirstArg := strings.TrimSpace(rargs[0])to classify each argument, which is correct - but the positional branch then stores the trimmed copy instead of the original argument, so any positional carrying deliberate whitespace is silently rewritten:A filename with a leading space, a message string, a pattern argument - all reach the action modified, with no error. The empty-string branch a few lines above already appends
rargs[0]untrimmed, so this change makes the non-empty branch consistent with its sibling: classify with the trimmed copy, append the original.One line changed in
command_parse.go, plus a regression test.Note: the lone-
-branch nearby has the same trimmed append, but that line is already being rewritten by #2419 (the bare-dash fix), so this PR deliberately does not touch it.