Support detailed help.

Any command/arg implementing the HelpProvider interface will be used to
provide arbitrarily detailed help.
This commit is contained in:
Alec Thomas
2018-08-14 14:41:27 +10:00
parent 27d2a08e53
commit f0bd1294a7
4 changed files with 31 additions and 5 deletions
+10
View File
@@ -25,6 +25,12 @@ type HelpOptions struct {
Compact bool
}
// HelpProvider can be implemented by commands/args to provide detailed help.
type HelpProvider interface {
// This string is formatted by go/doc and thus has the same formatting rules.
Help() string
}
// HelpPrinter is used to print context-sensitive help.
type HelpPrinter func(options HelpOptions, ctx *Context) error
@@ -77,6 +83,10 @@ func printNodeDetail(w *helpWriter, node *Node) {
if w.Summary {
return
}
if node.Detail != "" {
w.Print("")
w.Wrap(node.Detail)
}
if len(node.Positional) > 0 {
w.Print("")
w.Print("Arguments:")