Is there a way to get the command line string before it's parsed? The commandLineParams proc almost works but it removes the quotes.
import os
import strutils
echo commandLineParams().join(" ")
$ bin/tests/t -l=asdf --filename="file name with spaces"
-l=asdf --filename=file name with spaces
It doesn't exactly "remove" the quotes. The shell interprets them and stores into command-line arguments without them. A C program works the same way.
I think you want shellQuote.
https://nim-lang.org/docs/os.html#quoteShell%2Cstring
import os
import strutils
import sugar
#echo commandLineParams().join(" ")
proc main() =
let cl = sugar.collect(newSeq):
for p in commandLineParams():
os.quoteShell(p)
echo cl.join(" ")
main()
Result:
$ ./foo 1 "2 3" 4
1 '2 3' 4
Thanks for pointing out that the shell is responsible for quote handling. I was thinking there was of some general function like the windows GetCommandLine. I want to log the original string so I know what the user entered. I've decided that "echo $commandLineParams()" works for me.
I need to study up on the sugar stuff, looks powerful.