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
+6
View File
@@ -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 {