fizzed / blaze

Write your shell scripts on the JVM (java, kotlin, groovy, etc.)
109 stars 15 forks source link

Is it possible to provide arguments (args) to a script? #13

Closed TobseF closed 10 months ago

TobseF commented 6 years ago

Can I provide arguments which blaze passes to the script? So it would be possible to write:

fun main(args: Array<String>) {
    print(args)
}

and call java -jar blaze.jar -args mySuperArgument ?

I saw the blaze.conf property option. But in this way I have to add a blaze dependency / import to my script, which I want to avoid. And it's not flexible enough like arguments.

Or is the java -Dname=value the only possibility to pass an argument to a script? Which is not typical if i run the script without blaze, or want to test it with JUnit.

jjlauer commented 6 years ago

The -Dname=value method is the intended way of passing command-line arguments. You access them in your script as though they were config parameters. You don't need a .conf file, but if you did have one, you actually could supply defaults in the .conf and then simply override them on the command-line.

The main reason I never added true command-line arguments is that you can technically ask blaze to run multiple tasks at a time -- e.g. "blaze a b c" where a, b, and c are all separate tasks. You'd then require some convoluted strategy of "blaze a [args for a] b [args for b] c [args for c]" kind of syntax. Thus, I actually thought the config -Dname=value strategy for passing values is somewhat superior in a way.

On Tue, Apr 3, 2018 at 4:34 PM, Tobse notifications@github.com wrote:

Can I provide arguments which blaze passes to the script? So it would be possible to write:

fun main(args: Array) { print(args) }

and call java -jar blaze.jar -args mySuperArgument ?

I saw the blaze.conf https://github.com/fizzed/blaze/blob/master/docs/CONFIG.md property option. But in this way I have to add a blaze dependency / import to my script, which I want to avoid. And it's not flexible enough like arguments.

Or is the java -Dname=value the only possibility to pass an argument to a script? Which is not typical if i run the script without blaze, or want to test it with JUnit.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fizzed/blaze/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjwAmW0_dsT2pGr1JmCoZew10KYHxSOks5tk9zOgaJpZM4TFvhi .

TobseF commented 6 years ago

Thanks for the fast reply. Your idea with the config strategy sounds reasonable, and of course works pretty well in my case. To make it easier to migrate existing scripts something like a -a|--args options could help.

jjlauer commented 6 years ago

It'd be fairly straight forward to convert "-a arg" to simply by an alias to "-Da=arg" in the java boostrap code. I'd be supportive of a PR that implemented that kind of feature.

On Tue, Apr 3, 2018 at 5:45 PM, Tobse notifications@github.com wrote:

Thanks for the fast reply. Your idea with the config strategy sounds reasonable, and of course works pretty well in my case. To make it easier to migrate existing scripts something like a -a|--args options could help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fizzed/blaze/issues/13#issuecomment-378409695, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjwAggfT0t48AjkcR5sssanBh_S5SLjks5tk-2SgaJpZM4TFvhi .

jjlauer commented 10 months ago

Cleaning up old issues. This was addressed in recent blaze versions where "--argument" is now supported.