inim-repl / INim

Interactive Nim shell / REPL / Playground
MIT License
644 stars 23 forks source link

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

Open timotheecour opened 6 years ago

timotheecour commented 6 years ago

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

AndreiRegiani commented 6 years ago

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.

timotheecour commented 6 years ago

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:

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:
```nim
asdf
asdf
timotheecour commented 6 years ago

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)

Tangdongle commented 4 years ago

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: