Closed ajusa closed 6 years ago
Yep, this should be easy enough! I'll add it to the next release!
EDIT: Spoke too soon... It doesn't seem as trivial as I though, as the only things you can use in nim are getop2 (which is what I am using to parse args and opts) or os#commandLineParams. The latter however seems to strip quotes :(
For testing purposes, I created a raw-args symbol, and here's the result:
$ ./min -e:"raw-args puts" -par1 3 -par2 "a b c" --flag=true
("-e:raw-args puts" "-par1" "3" "-par2" "a b c" "--flag=true")
As you can see, it strips the quotes around the first parameter value.
Would this still be useful for your use case?
This doesn't quite work for my use case. I want the strings in quotes to be escaped automatically, like they are passed in. I want to be able to eval passed in options.
An example command with my program would be todo "a list item" add
, and I want it to give me a string containing "\"a list item\" add"
so I can evaluate the string and the sigil. The example you posted makes no difference whether something is in quotes.
I will see if I can find something in Nim or C that could be used to get the raw args passed in
(int todo swap remove #todo) :r
(string todo append #todo) :add
"db.txt" fread "\n" split =todo
args rest (() !=) (reverse "\"$1\" $2" swap % eval) when
0 :i todo (i print! ". " print! puts! i succ =i) foreach
todo "\n" join "db.txt" fwrite
I asked on the Nim gitter, and it appears that it is impossible to identify between strings and args unless you escape the string... which is a massive pain.
I think I'll just use the ask command to eval, and forget about command line args. I want the user to be able to extend it, so I need to eval. I know I could use a switch case, but this is much cooler. Thanks for creating this!
I know that
args
andopts
exist, but I need a way to get the raw input passed to the program.My use case is that I want to eval what comes after my program, which isn't possible since args gets rid of the quotation marks around strings.
Is it possible to include this in io or lang?