Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] inim -s:foo.nim -- args... => passes args to script foo.nim #35

Open
timotheecour opened this issue Jul 26, 2018 · 1 comment
Projects

Comments

@timotheecour
Copy link
Contributor

timotheecour commented Jul 26, 2018

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 dlang/dmd#7927)

[1] example for foo.nim:
bugs/inim/t03_cmdline.nim:

import os
for i in 1..paramCount():
  echo (i, paramStr(i))
@timotheecour timotheecour changed the title inim -s:foo.nim -- args... => passes args to script foo.nim [feature] inim -s:foo.nim -- args... => passes args to script foo.nim Jul 26, 2018
@0atman 0atman added this to Needs triage in Bug Triage Apr 8, 2020
@Tangdongle
Copy link
Collaborator

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Bug Triage
  
Needs triage
Development

No branches or pull requests

2 participants