command: expose print help
This is useful for custom help commands. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
312753924b
commit
416d93e880
@ -39,6 +39,9 @@ type (
|
|||||||
// NewCommand returns a new subcommand with direct command handling.
|
// NewCommand returns a new subcommand with direct command handling.
|
||||||
NewCommand(name, usage string, f HandlerFunc) (sub Flag[Node])
|
NewCommand(name, usage string, f HandlerFunc) (sub Flag[Node])
|
||||||
|
|
||||||
|
// PrintHelp prints a help message to the configured writer.
|
||||||
|
PrintHelp()
|
||||||
|
|
||||||
Flag[T]
|
Flag[T]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
var ErrHelp = errors.New("help requested")
|
var ErrHelp = errors.New("help requested")
|
||||||
|
|
||||||
|
func (n *node) PrintHelp() { _ = n.writeHelp() }
|
||||||
|
|
||||||
func (n *node) writeHelp() error {
|
func (n *node) writeHelp() error {
|
||||||
if _, err := fmt.Fprintf(n.out,
|
if _, err := fmt.Fprintf(n.out,
|
||||||
"\nUsage:\t%s [-h | --help]%s COMMAND [OPTIONS]\n",
|
"\nUsage:\t%s [-h | --help]%s COMMAND [OPTIONS]\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user