INim icon indicating copy to clipboard operation
INim copied to clipboard

`inim -i -s=file` to enter interactive inim session instead of exiting upon completion

Open timotheecour opened this issue 5 years ago • 4 comments

ipython3 --help:

If you  specify the option `-i` before the filename, it will enter an interactive
    IPython session after running the script, rather than exiting. Files ending
    in .py will be treated as normal Python, but files ending in .ipy can
    contain special IPython syntax (magic commands, shell expansions, etc.).

as ipython, inim should not exit inim shell upon completion of the script file, regardless of success/failure

  • [ ] NOTE: the .ipy point is interesting, we could have a .inim with same intent; would be useful eg for testing inim; that point is low priority though

timotheecour avatar Jul 26 '18 00:07 timotheecour

Pushed a fix to master, now it won't exit in case of failure when pre-loading a source code, it displays its errors/output if any (buffers as valid code if no errors) and opens the shell. I would prefer not to introduce a new argument -i.

Also, I'm thinking of allowing optional positional argument to do the same as -s, like inim foobar.nim, it was like this before supporting the new command-line arguments.

AndreiRegiani avatar Jul 26 '18 15:07 AndreiRegiani

I would prefer not to introduce a new argument -i.

I still think we should, but I'm happy to do a PR for it. Same rationale as ipython's use of -i, it allows distinguishing:

  • using inim for regular command line applications: eg in bash (or in any another program...)
bashvar=$(inim -s:scripts/coolfun.nim)
  • using inim interactively:
inim -i -s:scripts/coolfun.nim

That being said, we could make the default to be true if you prefer (these syntaxes are all now supported now that https://github.com/c-blake/cligen/issues/16 was closed)

## all these are interactive
inim -i -s:scripts/coolfun.nim
inim -i:true -s:scripts/coolfun.nim
inim -s:scripts/coolfun.nim

## all these are not interactive (ie, exit inim upon completion)
inim -i:false -s:scripts/coolfun.nim

Note, the following workaround cat tests/nim/inim/t01_ok.nim | inim --showHeader:false doesn't work, it has different semantics, eg:

cat bugs/inim/t02_stdin_vs_s.nim | inim --showHeader:false
Error: undeclared identifier: 'asdf'
Error: undeclared identifier: 'asdf'

inim -s:bugs/inim/t02_stdin_vs_s.nim --showHeader:false
Error: undeclared identifier: 'asdf'
inim>

bugs/inim/t02_stdin_vs_s.nim:

asdf
asdf

timotheecour avatar Jul 26 '18 20:07 timotheecour

Also, I'm thinking of allowing optional positional argument to do the same as -s, like inim foobar.nim, it was like this before supporting the new command-line arguments.

problem of positional arguments is if we later find need for other positional arguments, it'd lead to ambiguity; so maybe let's defer this until later? (as a workaround, an alias / bash function could be used in the meantime) NOTE: somewhat related to https://github.com/AndreiRegiani/INim/issues/35 (inim -s:foo.nim -- args... => passes args to script foo.nim #35)

timotheecour avatar Jul 26 '18 21:07 timotheecour

I reckon -s works as it should, it loads a source file into the buffer. Users have the option to pipe files into INim and have the piped script run and exit without jumping into a shell. I'm not sold that we need to add it, but I do have an idea or two. I almost guarantee it's faster to run nim -r on the script file you want to just run.

Should be go forth with this, we could add another INim flag like -r, --runNow or -f, --runFast to use exclusive of the -s. It accepts the same argument, ie a path to a source file, but it just runs it and exits instead.

I'm not keen on reversing the current behaviour for -s and I don't think adding another flag that goes with -s (one to tell INim to just run and exit) is cool.

Open to suggestions and for counter arguments to convince me that we still need this :rocket:

Tangdongle avatar Sep 07 '20 11:09 Tangdongle