-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add groups for commands in help #1003
Conversation
@aawsome I think this is a good addition. It's something I can put on the roadmap after 1.0.0 is released. |
Any updates on this? or any workarounds exist? |
This PR is being marked as stale due to a long period of inactivity |
I rebased this PR. |
@aawsome Maybe we can nudge @jharshman for some visibility. I think should be able to provide some direction. |
@aawsome would you mind adding some tests for this feature? |
Added some tests. Almost all new code is covered by these tests. The exception is |
Is there anything I can do to help getting this PR merged? |
This has been open for a while and would be pretty nice to have this merged. Any chance anyone could have a look at it? |
@aawsome Branch has conflicts. Could you rebase? So that if it's ready by the time @jharshman has a another look? |
is rebased. |
Hey, Any updates regarding this feature? |
@yuvalsosman, see #1496. |
Also close #1271 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small suggestions to cleanup a bit.
I haven't tested yet.
If you move the new
Yes please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I like this a lot. Nice job @aawsome. I put a bunch of minor suggestions about improving comments and such, but you should just be able to accept them in Github which should be very easy.
I believe the only thing remaining is when a command is not part of a group. I have created the "Administration Commands:" and "System Commands:" groups but "forgot" to assign the login
command to any group.
Currently we see this:
My CLI
Usage:
prog [command]
Available Commands:
login Login to the platform
System Commands:
config Configuration for the CLI
init Initialize the CLI
update Update the CLI
version Version information
Administration Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
Flags:
-h, --help help for prog
I think the section "Available Commands:" looks bad.
However, I would personally be ok with leaving it as is and saying that it is up to developers to properly define their groups and not leave commands without a group.
@jpmcb Thoughts?
@aawsome I'm finished with the review. Whenever you find time, if you can update, and then we'll be pretty much ready to merge 🎉 .
19fc3af
to
1f716e7
Compare
Co-authored-by: Marc Khouzam <[email protected]>
Thanks a lot for your review, @marckhouzam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally be ok with leaving it as is and saying that it is up to developers to properly define their groups and not leave commands without a group.
I think this is should be the desired behavior since it essentially makes this feature backwards compatible: if someone doesn't define any groups, I'd expect this the help section to continue to work like it does today.
I've pondered the design decisions this PR carries and while I think this implementation is good, I wonder if this would be due for a refactor down the road since people may want a way to do more interesting things with groups beyond matching on strings (i.e., a group struct with a superset of cobra commands). But we'd need to see if people would even want that.
TLDR: I think this is good for now and we can merge it to get this behavior in
Signed-off-by: Marc Khouzam <[email protected]>
I tested the latest version and it looked great. If no groups are defined at all we remain backwards-compatible and get:
If all subcommands have a group, we no longer get an empty "Available Commands:" line:
And if some commands have groups but some do not we get a new "Additional Commands:" section at the bottom:
@aawsome @jpmcb do you agree this is better? If not, we can just remove the top commit that I pushed.
That is interesting and may indeed have potential for improvement. But I also can't tell at the moment what that would look like and if it will be in demand. So I agree with @jpmcb that we should go ahead with this version, which we know people want, and see where it takes us. |
Just had a look at your commit. This is how I would have added these functionalities. So,your changes look good for me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @marckhouzam!!
I'd just like to say thank you from a backseat watcher and user of the library to @aawsome for bringing this over the finish line even after such a long time! And of course everyone else who helped along the way. |
Yes thank you @aawsome ! You have shown great professionalism in what can be considered a frustrating situation 🙂 The community will reap the rewards 🎉 |
If you don't mind, a follow-up question while adopting this: the groups appear in the order they are defined, but what about the commands in the group? Can we order them? It seems that currently this is alphabetical, which isn't usually very meaningful. Edit: Just found
so
does the trick. 👍 |
Adds the possibility to group the commands in the help message. Merge spf13/cobra#1003 closes #836 closes #1271
Adds the possibility to group the commands in the help message.
closes #836
closes #1271