-
Notifications
You must be signed in to change notification settings - Fork 440
Description
A CLI is supposed to return some exit code using e.g. System.exit(2)
if there is an error. But this should be called at the top level, and not several levels deep.
My application is calling the following to run the Runnable
application:
CommandLine.run(this, getArgs());
My application has a method-based subcommand—let's call it bar
. If there is an error (e.g. let's say that a command-line switch was invalid), how does the bar()
method return an error so that the main application can call System.exit()
appropriately?
On first glance it might appear that I should switch from using Runnable
to Callable
. But this irrelevant for method subcommands, which are processed differently. I can't throw an exception, because Picocli hijacks the handling of any errors inside execute(CommandLine parsed, List<Object> executionResult)
.
It appears that Picocli is collecting any return value from the subcommand methods into executionResult
. But how do I get those values back?
(Personally I almost wish I could just throw my own exception from the subcommands and somehow bypass Picocli and let my higher-level application handle them.)