-
Notifications
You must be signed in to change notification settings - Fork 420
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
Support subcommand methods in Groovy scripts #1191
Comments
Thanks for raising this! |
AnalysisLooking at this, I am finding various problems with the
So, how to fix this without breaking any scripts that depend on the above behaviour? WorkaroundOne idea to fix this, is that scripts override the // workaround for picocli 4.0 - 4.5.2
@Override
Object run() {
return getOrCreateCommandLine().execute(getScriptArguments())
} This works for scripts that do not override any of the PicocliBaseScript methods. Long-term Solution 1In a future release of // solution 1: use CommandLine.execute by default
// The below snippet shows how a script can override the `run` method to fall back to the legacy behaviour.
@Override
Object run() {
return legacyRun()
} This could potentially break existing scripts that did customization by overriding any of the PicocliBaseScript methods. Long-term Solution 2An alternative long-term solution is to document the workaround and recommend all Groovy scripts use it. // solution 2: use the legacy behaviour by default
// The below snippet shows how a script can override the `run` method to invoke CommandLine.execute.
@Override
Object run() {
return execute() // invokes `getOrCreateCommandLine().execute(getScriptArguments())`
} This preserves backwards compatibility but puts a burden on future Groovy script authors. The script does not "automatically do the right thing". Thoughts? |
I would vote for implementing long term solution 1. |
I don't have any idea about the number of users of Most scripts will work fine with Solution 1, but scripts that have customized behaviour by overriding any "hybrid" approachYet another idea is a "hybrid" approach where in addition to Solution 1, we install an Picocli's default parameterExceptionHandler is nicer (suggests typo corrections), and returns a different exit code than Hybrid approach has limited scopeEven in this hybrid approach, it may not be possible to invoke the following
These methods will not be called with Solution 1, even in the hybrid approach. So scripts that customized these methods may encounter problems. The hybrid approach has the risk that may fail to satisfy both new users (who I imagine prefer the default exception handlers), and existing users whose customization is not covered by the hybrid approach. |
|
Introducing a new I made some progress on this and pushed my changes to master. Documentation is still work in progress. Any review would be great. |
@attiand I think the work for this ticket is complete. To summarize:
This will be included in the upcoming picocli 4.6 release. |
@remkop looks good, works the way I hoped 👍 Thanks. |
I’m not sure if this is supposed to work, but it would be very cool if it did.
The groovy script seems to pick up the sub command in the usage help, but i can’t get the script to call the
commit
method.The text was updated successfully, but these errors were encountered: