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

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

Open jlbosse opened this issue 2 years ago • 2 comments

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.

jlbosse avatar Oct 20 '23 15:10 jlbosse

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!

Roger-luo avatar Oct 25 '23 17:10 Roger-luo

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

jlbosse avatar Oct 26 '23 15:10 jlbosse