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

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

Open
jlbosse opened this issue Oct 20, 2023 · 2 comments
Labels
codegen Julia AST codegen related issue enhancement New feature or request help wanted Extra attention is needed

Comments

@jlbosse
Copy link

jlbosse commented Oct 20, 2023

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
Copy link
Collaborator

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 Roger-luo added enhancement New feature or request help wanted Extra attention is needed codegen Julia AST codegen related issue labels Oct 25, 2023
@jlbosse
Copy link
Author

jlbosse commented Oct 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Julia AST codegen related issue enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants