Skip to content
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

Allow grouping of commands #684

Open
loilo opened this issue Oct 20, 2016 · 14 comments
Open

Allow grouping of commands #684

loilo opened this issue Oct 20, 2016 · 14 comments

Comments

@loilo
Copy link

loilo commented Oct 20, 2016

It's amazing that we have the possibility to group options under a certain headline.
It would be great though to be able to do the same with commands.

In case anyone's not convinced how that would be useful, I'll explain my personal use case:

I made a CLI tool that has some built-in commands but is pluggable in a way so commands can be added from outside.
I'd like to kind of set apart those commands from the built-in ones in the --help, maybe under a "Plugins" headline.

The most convenient way in my eyes would be to be able to group commands.

What do you think?

@nexdrew
Copy link
Member

nexdrew commented Oct 21, 2016

I like this idea. Unfortunately I think the commands API is a little cumbersome when it comes to adding new features (the latest at the time of this writing was command aliases).

For command modules, it's no problem, but for non-module commands, we have to either get creative or come up with a better API (something other than just tacking on new method arguments).

I'll give this some thought.

@loilo
Copy link
Author

loilo commented Oct 21, 2016

I thought so, that's the reason I didn't come up with a concrete example how that might look myself.
Just taking a glimpse at it there wasn't a quick way that would not have conflicted with the grouping of options.

@wmnnd
Copy link

wmnnd commented Apr 19, 2017

Would you accept a pull request that adds commandGroup(opts, groupName) that would work like group(opts, groupName) but for commands?

@itai-codefresh
Copy link

Any updates about this?
It is a very needed feature.
@wmnnd will you be able to expose your code so maybe we can use it?

@wmnnd
Copy link

wmnnd commented Jan 3, 2018

@itai-codefresh Nope, I ended up using nopt instead. You can check out dblsqd-cli to see how I implemented it.

@quilicicf
Copy link

That feature would be awesome indeed. I tried looking at the code to see if I could come up with an implementation but there are things I don't quite understand in the code.

From what I gather, a method commandGroup should be added in yargs.js. That method should work like group does but for commands, with a getCommandGroups method to get them.

Where I'm getting lost is with the preservedGroups and freeze stuff. I don't see tests related to that part of the code which makes it a bit harsh to understand.

I could probably try to implement something but I guess I'd need a little helping hand.

@lodo1995
Copy link

lodo1995 commented Jun 11, 2018

@nexdrew is there any news on this? It would be a great feature.

If providing the feature only for command modules is easy, you could start by providing only that; it would still be better than nothing.

For the non-module way of adding commands, I would suggest either groupCommand(<command-name>, <command-group>), mirroring group(<option-name>, <option-group>), or startGroup(<group-name>), which would put all subsequently defined commands in the group.

@bcoe
Copy link
Member

bcoe commented Nov 10, 2019

I continue to think this would be a slick feature, if anyone wants to take it on.

@bcoe bcoe added the triaged label Nov 10, 2019
@hungluu
Copy link

hungluu commented Nov 21, 2019

+1 on this. I recently built an extensible CLI app with growing number of commands. The command groups (with an alternative / or customisable --help's command list generation) will make make things more comprehensible.

@chrfrenning
Copy link

+1 - still relevant 2ish years later - anything that grows beyond 4-5 commands will benefit from this in terms of usability.

@JacobMGEvans
Copy link
Contributor

+1 still relevant, many commands in the CLI we are building.

@jcs090218
Copy link

+1

@stackblaze

This comment was marked as resolved.

@shadowspawn

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests