INim
INim copied to clipboard
[feature] `inim -s:foo.nim -- args...` => passes args to script foo.nim
proposal
inim -s:foo.nim -- arg1 arg2 # passes arguments arg1, arg2 to script foo.nim (eg see [1])
cat foo.nim | inim -- arg1 arg2
inim -- arg1 arg2 # now typing `echo paramStr(1)` on inim prompt would print `arg1`
The --
is needed
it avoids unnecessary ambiguities (and makes it easy to parse visually which is an argument to inim, which is an argument to the script)
eg: with --
required:
inim -s:foo.nim -- -h # -h passed to foo
inim -s:foo.nim -h -- # -h passed to inim; same as: `inim -s:foo.nim -h`
cat foo.nim | inim -- -s:bar.nim # -s:bar.nim bassed to foo (contrived example...)
if --
were not required:
inim -s:foo.nim -h # ambiguous: is -h a inim argument or an argument for foo? this ambiguity affects programs like grep which add a `-e` to disambiguate when patterns begin with `-`
cat foo.nim | inim -s:bar.nim # ambiguous
here's how other programs handle passing arguments:
- programs that read interactively from stdin (such as inim):
ipython ipython_args... -- args... # this is same as my suggestion
lldb lldb_args... -- foo args... # similar, because -- is used as delimiter
gdb gdb_args... --args foo args... # similar, because --args is used as delimiter
- programs that don't read interactively from stdin:
nim nim_arg(with -r)... foo.nim args... # note, nim doesn't interactively read from stdin (unless `-` is passed IIRC?), so not having `--` is less of an issue for it
dmd dmd_args... -run foo.d args...
(dmd's case is bad, see https://github.com/dlang/dmd/pull/7927)
[1] example for foo.nim: bugs/inim/t03_cmdline.nim:
import os
for i in 1..paramCount():
echo (i, paramStr(i))
It looks like it might be difficult to do this with cligen and use the --
parameter. AFAIK, each argument to inim needs to have a corresponding argument in the dispatching function, where --
would be an illegal parameter name. It might be possible to add an "extra args" kind of parameter (like -a or --scriptArgs) that will in turn pass it to the nim compiler when compiling the INim buffer (in which the srcFile is injected on startup)