comonicon / Comonicon.jl

Your best CLI generator in JuliaLang
https://comonicon.org
MIT License
282 stars 25 forks source link

Only run command_main() when calling from command line #265

Open jlbosse opened 10 months ago

jlbosse commented 10 months ago

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

Roger-luo commented 10 months ago

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+.

jlbosse commented 10 months ago

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 ?

Roger-luo commented 10 months ago

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?

jlbosse commented 10 months ago

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?

Roger-luo commented 10 months ago

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