-
Notifications
You must be signed in to change notification settings - Fork 423
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
What to do for multiple commands #518
Comments
Hi @NagendraHegde , please take a look at this example: It demonstrates how to code a top-level command with a single subcommand. It is a good idea to make all your commands implement
Picocli will execute the most specific subcommand that the user specified. So, for example, if you have a command hierarchy like this:
Then, when the user invokes |
@NagendraHegde Did this answer your question? |
@NagendraHegde Were you able to make progress or do you have follow-up questions? |
@NagendraHegde Can this ticket be closed? |
Since you are talking about top-level commands (not subcommands), every top-level command will need a separate class with its own |
If your application has multiple top-level commands, each of these will need its own
Your jar can only have one Main-Class in its manifest, and that will be the command when users invoke the jar as an application, like this:
If you have multiple top-level commands, what people often do is provide multiple script files (shell script or batch scripts) that the end user can invoke. For example, for Windows:
This allows end users to call the command with its script name. |
Closing this ticket. Feel free to reopen if you want further clarification |
I have the same problem and I find the last comment more as a workaround than a real solution. This jar will receive args[] so it has all what it needs to have in order to interprete parameters. I don't see why we should require some bash or batch scripts here. Isn't there a better solution which could work with picocli without having to use a script ? |
@sebastienvermeille, would you mind creating a new ticket to explain your use case? |
@sebastienvermeille The OP never replied after multiple comments so it’s hard to say whether I understood their problem. I’m happy to help but it would be good if you could explain in your own words what it is you’re trying to achieve. |
@remkop sure if can help somehow I will :) |
@NagendraHegde I feel that I didn’t explain things very well in response to your question. Please take a look at #641: perhaps my answer there is more clear and hopefully the discussion on that ticket is useful to you as well. |
Hi Team,
Below is the situation I am facing:
I want to build a cli tool with picocli. I want to bundle it in a fat jar and give it to the users so that they can use it as a cli tool.
The tool is going to have multiple commands. Below is the format:
java commandone -a somevalue
java commandtwo -b someothervalue
For these, i can write classes for each individual commands with the help of @command annotation.
e.g:
@command(name="commandcone")
public class CommandOne implements Runnable { ... }
But the problem is, all the example given in the wiki demand to have public static void main() in the class and manually call CommandLine.run( ... ) in order to get the commands executed.
In the case of a tool having multiple commands (not subcommands), what do I do? I can not write main method to each class that i create for a command, right?
Do i manually write the routing for different commands? or is there a mechanism available already in picocli and I am unable to find it properly?
Please help. (btw other features are cool and you guys rock :) )
The text was updated successfully, but these errors were encountered: