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

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

Open
1 task
timotheecour opened this issue Jul 26, 2018 · 4 comments
Projects

Comments

@timotheecour
Copy link
Contributor

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 timotheecour changed the title inim -i -s=file to enter interactive inim session inim -i -s=file to enter interactive inim session instead of exiting upon completion Jul 26, 2018
@AndreiRegiani
Copy link
Member

AndreiRegiani commented Jul 26, 2018

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
Copy link
Contributor Author

timotheecour commented Jul 26, 2018

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 c-blake/cligen#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
Copy link
Contributor Author

timotheecour commented Jul 26, 2018

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 #35 (inim -s:foo.nim -- args... => passes args to script foo.nim #35)

@0atman 0atman added this to Needs triage in Bug Triage Apr 8, 2020
@Tangdongle
Copy link
Collaborator

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 🚀

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

3 participants