Support detailed help.
Any command/arg implementing the HelpProvider interface will be used to provide arbitrarily detailed help.
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var helpProviderType = reflect.TypeOf((*HelpProvider)(nil)).Elem()
|
||||
|
||||
func build(k *Kong, ast interface{}) (app *Application, err error) {
|
||||
defer catch(&err)
|
||||
v := reflect.ValueOf(ast)
|
||||
@@ -107,6 +109,10 @@ func buildChild(k *Kong, node *Node, typ NodeType, v reflect.Value, ft reflect.S
|
||||
child.Help = tag.Help
|
||||
child.Hidden = tag.Hidden
|
||||
|
||||
if fv.Type().Implements(helpProviderType) {
|
||||
child.Detail = fv.Interface().(HelpProvider).Help()
|
||||
}
|
||||
|
||||
// A branching argument. This is a bit hairy, as we let buildNode() do the parsing, then check that
|
||||
// a positional argument is provided to the child, and move it to the branching argument field.
|
||||
if tag.Arg {
|
||||
|
||||
Reference in New Issue
Block a user