add a flag to disable autogen tag in man and markdown generators
Inherits from parent commands all the way to root
This commit is contained in:
committed by
Steve Francia
parent
e5762054c9
commit
5144a3aa19
20
command.go
20
command.go
@ -93,6 +93,8 @@ type Command struct {
|
||||
PersistentPostRun func(cmd *Command, args []string)
|
||||
// PersistentPostRunE: PersistentPostRun but returns an error
|
||||
PersistentPostRunE func(cmd *Command, args []string) error
|
||||
// DisableAutoGenTag remove
|
||||
DisableAutoGenTag bool
|
||||
// Commands is the list of commands supported by this program.
|
||||
commands []*Command
|
||||
// Parent Command for this command
|
||||
@ -474,15 +476,29 @@ func (c *Command) SuggestionsFor(typedName string) []string {
|
||||
return suggestions
|
||||
}
|
||||
|
||||
func (c *Command) VisitParents(fn func(*Command)) {
|
||||
var traverse func(*Command) *Command
|
||||
|
||||
traverse = func(x *Command) *Command {
|
||||
if x != c {
|
||||
fn(x)
|
||||
}
|
||||
if x.HasParent() {
|
||||
return traverse(x.parent)
|
||||
}
|
||||
return x
|
||||
}
|
||||
traverse(c)
|
||||
}
|
||||
|
||||
func (c *Command) Root() *Command {
|
||||
var findRoot func(*Command) *Command
|
||||
|
||||
findRoot = func(x *Command) *Command {
|
||||
if x.HasParent() {
|
||||
return findRoot(x.parent)
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
return findRoot(c)
|
||||
|
Reference in New Issue
Block a user