jbang
jbang copied to clipboard
Support a unique directive to pass JBang CLI options
Is your feature request related to a problem? Please describe.
After further reflection on the issue #1803, now I think that it'd be great if JBang provides another directive //JBANG_OPTIONS <jbang_options>, which is similar to //JAVAC_OPTIONS or //JAVA_OPTIONS but solely for the JBang CLI options https://www.jbang.dev/documentation/guide/latest/cli/jbang-run.html#_options.
After #1803, I think it's not a good design to only allow users to pass JBang options in the first line of a script, considering the possible bad effects by misconfigurations (see #1803 for more details):
///usr/bin/env jbang <options> "$0" "$@" ; exit $?
Describe the solution you'd like
Support a new directive //JBANG_OPTIONS:
///usr/bin/env jbang "$0" "$@" ; exit $?
...
//JBANG_OPTIONS --quiet --offline --javaagent=org.jolokia:jolokia-agent-jvm:2.0.2:javaagent=host=0.0.0.0,port=8888
This way, any misconfigurations in the //JBANG_OPTIONS line would never result in the naughty infinite loops.
Describe alternatives you've considered
It can be a different name like //JBANG_PARAMETERS or //JBANG_CLI_OPTIONS. Or, can any of the existing directives already serve the exact purpose?
Additional context The original issue:
- #1803
But which options would you like to pass? I think most (of the useful) options you can pass are already available as //-tags. Are we missing some?
Hmmm what I do see is perhaps a lack of documentation... @maxandersen do we really have no list of supported //-tags in our docs?? I'm trying to find it but it's because I still haven't had any coffee and I keep missing it or it's because it doesn't exist.
Edit: and the section on java agents mentions the CLI option --javaagent but not the tag //JAVAAGENT.
I think most (of the useful) options you can pass are already available as //-tags.
Oh, could you explain how I can use //-tags? Can we do something like below already?
//--quiet
//--offline
//--javaagent=org.jolokia:jolokia-agent-jvm:2.0.2:javaagent=host=0.0.0.0,port=8888
Edit: and the section on java agents mentions the CLI option --javaagent but not the tag //JAVAAGENT.
If I read the doc correctly, I don't think //JAVAAGENT is something I could use in substitute for --javaagent JBang option. It appears to be used for creating an agent with JBang script, not for attaching an agent to the running script.
Hmm, it doesn't look like //-tag works for me. This script:
///usr/bin/env jbang "$0" "$@" ; exit $?
//--quiet
// //DEPS <dependency1> <dependency2>
import static java.lang.System.*;
public class hello {
public static void main(String... args) {
out.println("Hello World");
}
}
still outputs like below when executing:
./hello.java
[jbang] Building jar for hello.java...
Hello World
neither //-quiet nor //--quiet works for me. JBang version is 0.116.0.
Having a jbang options inside the source files is problematic for several reasons:
- does not work for non-source launches
- would require the source files before we have the rest of the config options
so that is not a viable solution.
The prefix header is the right place to have it or if you really must (i.e. for windows) create an alias/batch command that does the call like for any other CLI.
@maxandersen Thanks. I understand your point.
But as Tako suggested, there are already some tags that are supported, e.g. //DEPS, //JAVA_OPTIONS, //JAVAC_OPTIONS, etc. I even tried different tags, but I found that there are some other options that doen't seem to be supported: e.g. //DEBUG, //NATIVE, //QUIET.
It seems a bit inconsistent to me:
- Work:
//DEPS,//JAVA,//JAVA_OPTIONS,//JAVAC_OPTIONS,//REPOS - Not seem to work:
//DEBUG,//NATIVE,//QUIET - Work but have different meaning:
//JAVAAGENT
In this issue, among these, what I'd like to use most is //JAVAAGENT, because I found it most error-prone to use in the file header line. If the following worked, my problem would have been resolved.
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVAAGENT org.jolokia:jolokia-agent-jvm:2.0.3:javaagent=discoveryEnabled=true,serializeLong=number