How to use JCommander for groups of commands?

88 views
Skip to first unread message

Dominik Kaspar

unread,
Oct 2, 2017, 9:29:38 AM10/2/17
to jcommander
Hi,

I just came across JCommander for the first time while trying to create a command-line parser.
My first attempts have succeeded to parse options and commands, but I'm unsure about how to model something like grouped commands.
The tool I try to develop has several command categories like "user" and "group" and each of the them have some actions like "list", "create", "delete".
Some of the actions have additional parameters, some do not.

   user list
   user create
-firstName <first> -lastName <last>
   user
delete -id <id>

   
group list
   
group create -name <name>

How can I do that with JCommander?
I tried with a CommandUser and a CommandGroup, but then I don't know how to model the actions, with are basically nested commands.

I could create a new command for each action like UserListCommand, UserCreateCommand...
What is the recommended way?

Best regards,
Dominik

Cédric Beust ♔

unread,
Oct 2, 2017, 9:32:18 AM10/2/17
to jcommander
Hi Dominik,

Right now, I can't think of a better way than using commands with variable arities and performing the additional parsing in these listeners.

Feel free to propose something more structured if you can think of something.

-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages