jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Allow "apps" to pass options to Jbang

Open quintesse opened this issue 3 years ago • 5 comments
trafficstars

See this discussion https://github.com/jbangdev/jbang/discussions/1441#discussioncomment-3508381

An idea I had is that we could perhaps do something like this (assume an app called "myapp" exists):

$ myapp some args for myapp
$ myapp --debug -Dfoo=bar -- some args for myapp

Meaning that if an "--" argument is present all arguments before it are passed to Jbang while all arguments after it are passed to the app.

If it necessary to pass "--" to the app you can always do:

$ myapp -- an arg with -- for myapp

The question is if we want to make this a standard feature of the jbang run command or that we add a special option for this behaviour, eg the following two lines would basically be equivalent:

$ myapp --debug -Dfoo=bar -- some args for myapp
$ jbang run --app myapp.java --debug -Dfoo=bar -- some args for myapp

I'm leaning towards the latter option because it preserves complete backward compatibility with any existing scripts.

NB: the option could be flagged as hidden so as not to make the UI/help more complex

quintesse avatar Aug 30 '22 17:08 quintesse

this would require us to add custom code to the app...not following how this would work when its compiled to native ?

maxandersen avatar Sep 01 '22 05:09 maxandersen

i.e.

$ myapp --debug -Dfoo=bar -- some args for myapp

Here jbang is not necessarily involved so we can't adjust.

$ jbang run --app myapp.java --debug -Dfoo=bar -- some args for myapp

not following - how is thatdifferent from run today?

maxandersen avatar Sep 01 '22 05:09 maxandersen

jbang is not engaged at the time the parsing kicks in...I don't see a clean way of having a app set these without using the env var trick.

We could make it part of jbang app install though so the launch script gets it baked in.

maxandersen avatar Sep 01 '22 05:09 maxandersen

.not following how this would work when its compiled to native ?

It would just not work when compiled to native. It's something that would only work when run using jbang. Which is okay because if it's compiled to native none of the jbang or java options are relevant anyway, It's just a nicer way to be able to pass options to jbang. Otherwise installing an app comes with disadvantages/restrictions over running it using jbang run, which seems like a pity.

NB: remember that JBANG_JAVA_OPTIONS jbang run .... only works nicely on Linux and Mac, you can't do this on Windows. You'd always have to use set and then don't forget to use unset afterwards or it will affect all jbang invocations. So having something like this would be nice.

quintesse avatar Sep 01 '22 08:09 quintesse

We could make it part of jbang app install though so the launch script gets it baked in.

True, I thought of that as well, but then you could just as well add the options to the script using //JAVA_OPTIONS, so I don't think that would solve the issue of not being able to easily pass jbang/java options when using an installed app.

quintesse avatar Sep 01 '22 08:09 quintesse