remove group id of the help command and completion command

This commit is contained in:
Jun Nishimura 2023-07-27 23:51:46 +09:00
parent a2edfa4d9a
commit 8a2769858c

View file

@ -330,12 +330,25 @@ func (c *Command) SetHelpCommandGroupID(groupID string) {
c.helpCommandGroupID = groupID c.helpCommandGroupID = groupID
} }
// resetHelpCommandGroupID resets the group id of the help command.
func (c *Command) resetHelpCommandGroupID() {
if c.helpCommand != nil {
c.helpCommand.GroupID = ""
}
c.helpCommandGroupID = ""
}
// SetCompletionCommandGroupID sets the group id of the completion command. // SetCompletionCommandGroupID sets the group id of the completion command.
func (c *Command) SetCompletionCommandGroupID(groupID string) { func (c *Command) SetCompletionCommandGroupID(groupID string) {
// completionCommandGroupID is used if no completion command is defined by the user // completionCommandGroupID is used if no completion command is defined by the user
c.Root().completionCommandGroupID = groupID c.Root().completionCommandGroupID = groupID
} }
// resetCompletionCommandGroupID resets the group id of the completion command.
func (c *Command) resetCompletionCommandGroupID() {
c.Root().completionCommandGroupID = ""
}
// SetHelpTemplate sets help template to be used. Application can use it to set custom template. // SetHelpTemplate sets help template to be used. Application can use it to set custom template.
func (c *Command) SetHelpTemplate(s string) { func (c *Command) SetHelpTemplate(s string) {
c.helpTemplate = s c.helpTemplate = s
@ -1331,6 +1344,17 @@ main:
if command.GroupID == groupID { if command.GroupID == groupID {
command.GroupID = "" command.GroupID = ""
} }
if command.helpCommandGroupID == groupID {
command.resetHelpCommandGroupID()
}
}
}
for _, groupID := range groupIDs {
if c.helpCommandGroupID == groupID {
c.resetHelpCommandGroupID()
}
if c.Root().completionCommandGroupID == groupID {
c.resetCompletionCommandGroupID()
} }
} }
} }