-
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
Beginner question: How to call top command and sub command #687
Comments
I assume that the So, This explains why we see the "Unmatched argument: rla" error when specifying another "rla" command line argument after The correct way to invoke the
|
One more thing: you need to let the This is the reason for the second error "(com.XXXXXXXXXX.App@4802796d) is not Method, Runnable or Callable". |
Thank you very much Remko, so I guess I was on the right path somehow. Just another question if you don't mind: So it's working now. But is it ok to have an empty run() method then? What would be the best practice if you only want to use sub commands and don't need the run() method / top level command? I appreciate your support here which often also covers questions which shouldn't bother you :) |
Yes, that is fine.
There is an outstanding request for this: #625. Meanwhile, the workaround is to print an error message (and maybe show usage help) in the top command's |
Thank you! I have re-added the Runnable and run-Method (including an error message which gets printed if the top level command is called) to the class. But I have a slighly differnent main-method setup:
So I want to use CommandLine.RunAll() to make it possible that multiple sub commands are executed with one call to the application. In combination with your explanation in #687 (comment) when using "java -jar rla.jar usecase1 -uc1p a usecase2 -uc2p b", the top-level command is therefore always executed and thus the error message inside the run() gets always printed. (What I read in #625 is a slightly different requirement I think: Making the subcommands required additionally to the top-level command.) So my question would be: Is it possible to only call the sub methods when using CommandLine.RunAll()? :) E: Oops, is it even possible to call multiple (independent from each other) sub commands at once? |
I think what you are looking for is This is the default and is what most applications use. |
Ja, in this case (multiple non-hierarchical sub commands not possible with one call) it makes sense to use RunLast then. Thank you :) |
You’re welcome! |
Hi,
I have an application which requires a base set of input parameters.
I have two use cases which require all of these parameters but each of them also a different input parameter on top.
So I thought it would be the best to call the top-level command with the base set of input parameters plus the sub command method which processes the corresponding use case then with one call to the application.
I read the following chapters: https://picocli.info/#_subcommand_methods and https://picocli.info/#_convenience_methods_for_subcommands
So it should be something like this I guess - similiar to what is shown in the first link of the documentation (chapter 18.2.1):
Results:
With calling the top command
java -jar "rla.jar" rla -bb "z" usecase1 -uc1p "a":
Or only calling the subcommand:
java -jar "rla.jar" usecase1 -uc1p "a":
How do I call the app correctly :D?
The text was updated successfully, but these errors were encountered: