jcommander icon indicating copy to clipboard operation
jcommander copied to clipboard

SubCommands

Open mkarg opened this issue 6 years ago • 7 comments

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 avatar Jul 03 '19 05:07 mkarg

@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?

mkarg avatar Jul 08 '19 21:07 mkarg

Hi @mkarg,

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

cbeust avatar Jul 08 '19 21:07 cbeust

@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 avatar Jul 08 '19 21:07 mkarg

@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. :-)

mkarg avatar Jul 09 '19 20:07 mkarg

That's awesome to hear :)

cbeust avatar Jul 09 '19 20:07 cbeust

@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 avatar Oct 26 '19 05:10 david-truong

@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

mkarg avatar Oct 26 '19 09:10 mkarg