comonicon / Comonicon.jl

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

[feature request] Run `command_main()` only when running script frome the command line #260

Open jlbosse opened 10 months ago

jlbosse commented 10 months ago

It would be great if command_main() only gets called when the script is run from the command line and not when it is include()ed e.g. in a REPL session. This would allow one to have a julia script that is on one hand usable as a CLI, but on the other hand one can also do include(myscript.jl) in a REPL session or other script and use the functionality defined in myscript.jl from there.

I suppose wrapping the call in a if abspath(PROGRAM_FILE) == @__FILE__ command_main() end would do that trick.

Roger-luo commented 10 months ago

I think this is possible. And I like this idea! could be supported by adding your change here https://github.com/comonicon/Comonicon.jl/blob/main/src/frontend/cast.jl#L461, please feel free to open a PR for this!

jlbosse commented 10 months ago

Great, I will try to find some time create a PR for this then!