-
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 remove group method for command #1997
base: main
Are you sure you want to change the base?
Conversation
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.
This makes sense to me and looks to be on par with how RemoveCommand
works 👍🏼
@@ -1862,6 +1862,61 @@ func TestAddGroup(t *testing.T) { | |||
checkStringContains(t, output, "\nTest group\n cmd") | |||
} | |||
|
|||
func TestRemoveSingleGroup(t *testing.T) { |
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.
Thanks for adding tests! Definitely makes it easier to validate!!
@jpmcb One question, do I need to ask one more person to review this PR to merge it into the main branch? |
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.
A thought I had. If the user calls remove group with an invalid group ID, the current logic will simply ignore it. Is that what we want or do you prefer to help the developer notice their mistake?
command.go
Outdated
@@ -1311,6 +1311,30 @@ func (c *Command) AddGroup(groups ...*Group) { | |||
c.commandgroups = append(c.commandgroups, groups...) | |||
} | |||
|
|||
// RemoveGroup removes one or more command groups to this parent command. | |||
func (c *Command) RemoveGroup(groupIDs ...string) { |
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’m not sure, but I don’t think this will allow removing a group for the help or completion commands. Do we want to support removing groups for those two commands?
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.
Interesting use case. I guess in theory someone might want to remove those from a group that have been added. But they are also sort of the "default" commands you get. What do you think Marc?
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.
In my opinion, I would like cobra to give users as much freedom of development as possible. It is up to the developers to decide whether they want to keep the help
and completion
commands as existing groupies or remove them.
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 agree and I'm 100% for freedom of use. It more just becomes a matter of not breaking long standing existing features. But this is new functionality anyways. So I'm good with it!
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 fixed as follows. If the group id passed as argument match, the group id of the help and completion command is reset in the RemoveGroup method. I would appreciate it if you check the code again.
initialize -^> reset
@marckhouzam @jpmcb
I thought it would be better to output an error if the expected group does not disappear as a result of calling the What do you think. |
Overview
This PR is about #1911.
Sorry, I missed that a PR(#1912) has already been submitted regarding this Issue.
However, it appears that a PR has not been updated, so I am submitting this just in case.
I added
RemoveGroup
method for command. RemoveGroup method removes groups from commandgroups and at the same time initializes the command's groupID.Related Issue
Related PR