cbeust / jcommander

Command line parsing framework for Java
Apache License 2.0
1.95k stars 333 forks source link

SubCommands #472

Open mkarg opened 5 years ago

mkarg commented 5 years ago

Some CLI utilities use multi-word commands alias "Sub Commands": docker container list <options>.

It would be great if JCommander would support the registration of sub commands with unlimited depth.

mkarg commented 5 years ago

@cbeust Cedric, if you agree about the general benefit of this feature, we would be happy to provide a PR. Can you please deliver your judgement?

cbeust commented 5 years ago

Hi @mkarg,

No objection to the idea, but a bit concerned how big that PR would be. Happy to review it.

mkarg commented 5 years ago

@cbeust I will assign this task to a new coder we hired. He could start work on that in Q4. As commands are internally JCommander instances, it shouldn't need to much change, as we could call JCommander.addCommand() on that sub-JCommander instances and let them parse the command in turn.

mkarg commented 5 years ago

@cbeust FYI, today we implemented a PoC for subcommands using unchanged current JCommander, and it worked like a charm. In fact, it works so good that we decided to take the PoC into production. So I think you don't need to worry about the size of the PR. :-)

cbeust commented 5 years ago

That's awesome to hear :)

david-truong commented 4 years ago

@mkarg can you share your PoC? We ended up adding a subcommand with a space in it i.e. "container list" and we were shocked but glad it worked. I was wondering if you took a similar approach or had a different implementation.

mkarg commented 4 years ago

@mkarg can you share your PoC? We ended up adding a subcommand with a space in it i.e. "container list" and we were shocked but glad it worked. I was wondering if you took a similar approach or had a different implementation.

@david-truong https://gist.github.com/mkarg/9d9ca23e6da32b47c7fadaf10ae16ba6