Hide sub-tree when parent is hidden.

This commit is contained in:
Alec Thomas
2018-11-14 10:01:45 +11:00
parent 010e3134ca
commit aedca401da
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -67,7 +67,7 @@ func printApp(w *helpWriter, app *Application) {
if !w.NoAppSummary {
w.Printf("Usage: %s%s", app.Name, app.Summary())
}
printNodeDetail(w, app.Node)
printNodeDetail(w, app.Node, true)
cmds := app.Leaves(true)
if len(cmds) > 0 && app.HelpFlag != nil {
w.Print("")
@@ -83,14 +83,14 @@ func printCommand(w *helpWriter, app *Application, cmd *Command) {
if !w.NoAppSummary {
w.Printf("Usage: %s %s", app.Name, cmd.Summary())
}
printNodeDetail(w, cmd)
printNodeDetail(w, cmd, false)
if w.Summary && app.HelpFlag != nil {
w.Print("")
w.Printf(`Run "%s --help" for more information.`, cmd.FullPath())
}
}
func printNodeDetail(w *helpWriter, node *Node) {
func printNodeDetail(w *helpWriter, node *Node, hide bool) {
if node.Help != "" {
w.Print("")
w.Wrap(node.Help)
@@ -112,7 +112,7 @@ func printNodeDetail(w *helpWriter, node *Node) {
w.Print("Flags:")
writeFlags(w.Indent(), flags)
}
cmds := node.Leaves(true)
cmds := node.Leaves(hide)
if len(cmds) > 0 {
w.Print("")
w.Print("Commands:")
+1 -1
View File
@@ -113,7 +113,7 @@ func (n *Node) Leaves(hide bool) (out []*Node) {
}
if node, ok := nd.(*Node); ok {
if hide && node.Hidden {
return next(nil)
return nil
}
if len(node.Children) == 0 && node.Type != ApplicationNode {
out = append(out, node)