Comonicon.jl icon indicating copy to clipboard operation
Comonicon.jl copied to clipboard

Only run command_main() when calling from command line

Open jlbosse opened this issue 2 years ago • 5 comments

Wrapped the call of command_main() in an if abspath(PROGRAM_FILE) == @__FILE__ to run it only if the sript is directly called from the command line. This makes it possible to include() Comonicon scripts as well and use the functions defined in them in other applications as well.

This addresses https://github.com/comonicon/Comonicon.jl/issues/260

Let me know if you also want me to add a sentence or two about this changed behaviour to the documentation

jlbosse avatar Oct 30 '23 10:10 jlbosse

I just realized #257 is related to this, the new behavior of Julia's entry point is basically what this PR implements, but I'm not sure what's the best way of supporting this now given this is a 1.10+ feature and we are supporting all 1.6+.

Roger-luo avatar Oct 30 '23 18:10 Roger-luo

AFAICT the question of what happens with the @main macro (and if it simply gets renamed to e.g. @app) and if we automatically run command_main() when includeing a Comonicon based script are independent?

Or did you have plans to make bigger changes than renaming @main to fix #257 ?

jlbosse avatar Oct 31 '23 12:10 jlbosse

maybe let's double check with @Keno, IIUC after shipping @main from Base if main is defined then the behaviour in this PR is supported by Julia already?

Roger-luo avatar Oct 31 '23 14:10 Roger-luo

Ah yes, it makes sense to see what Base.@main will do. I suppose there will be a suggested way to also support older julia versions, similar to the way there are these instructions to make weak dependencies work on older julia versions?

jlbosse avatar Nov 03 '23 10:11 jlbosse

Yeah so I think we will have to wait for something like that before merging this PR.

Roger-luo avatar Nov 03 '23 17:11 Roger-luo