Hello,
why I add parameter in command line with whiutespace?
echo parseCmdLine("""---title:"new title with whitespace" """)
parse:
@["---title:new", "title", "with", "whitespace\""]
Module works similarly:
opt cmdLongOption ---title:new
opt cmdArgument title
opt cmdArgument with
opt cmdArgument whitespace"
I can one Option with value "new title with whitespace"
thanks
this actually works for me:
import os
echo parseCmdLine("""---title:"new title with whitespace" """)
output:
@["---title:new title with whitespace"]
i'm currently on nim 1.6.10 [Windows: amd64]
thanks,
it seems to depend on the system settings
Im use Linux Manjaro (Mabox), fish shell (when I use bash, the result is the same).
What do you use?
thanks
Possibly helpful. The impl on Windows & Unix differs (big when and documented differences in lib/std/cmdline.nim). On Linux one sees (instead of what @enthus1ast describes):
import os
let x = r"""--title "new title with whitespace""""
# ^space needed can skip 1^
echo "inp: ", x.repr
echo "prs: ", x.parseCmdLine
#Output:
# inp: "--title \"new title with whitespace\""
# prs: @["--title", "new title with whitespace"]
Doing full shell lexing (&| a variety of string splitters) was discussed in a PR which had trouble getting merged due to detailed PR mechanics.There is a bug in parseCmdLine when not on windows.
https://github.com/nim-lang/Nim/issues/14343
this line should probably be:
while i < c.len and c[i] > ' ' and not (c[i] in {'\'','"'} ):
Oh, yeah, FWIW, @domogled's apparent intent can be gotten with
let x = r""""--title:new title with whitespace""""
# ^start with " can skip 1^
on both Linux & Windows. Not great, but maybe not totally useless.
There are "better" external things to do X for most X in the stdlib. Forum search fails me at the moment, but at some point Araq said something like "stdlib cannot keep up with anything!" There have been big discussions & experiments on evolving it with inconclusive results. Repeating all that here seems less prudent than a new Forum thread.
FWIW, I was ok with that PR under a new name/etc. as it was evolving to. I just thought imposing a need for try/except where it wasn't before was needlessly disruptive (and I took issue with what I thought weak arguments and an overly narrow perspective).