command: hide internal commands
This marks commands as internal via a magic usage string. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
416d93e880
commit
647c6ea21b
@ -6,6 +6,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// UsageInternal causes the command to be hidden from help text when set as the usage string.
|
||||
const UsageInternal = "internal"
|
||||
|
||||
type (
|
||||
// HandlerFunc is called when matching a directly handled subcommand tree.
|
||||
HandlerFunc = func(args []string) error
|
||||
|
@ -44,8 +44,10 @@ func (n *node) writeCommands(w io.Writer) error {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, "\t%s\t%s\n", n.name, n.usage); err != nil {
|
||||
return err
|
||||
if n.usage != UsageInternal {
|
||||
if _, err := fmt.Fprintf(w, "\t%s\t%s\n", n.name, n.usage); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return n.next.writeCommands(w)
|
||||
}
|
||||
|
@ -289,6 +289,7 @@ func buildTestCommand(wout, wlog io.Writer) (c command.Command) {
|
||||
})
|
||||
|
||||
c.New("empty", "empty subcommand")
|
||||
c.New("hidden", command.UsageInternal)
|
||||
|
||||
c.New("join", "wraps strings.Join").
|
||||
Command("out", "write result to wout", func(args []string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user