diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-02-23 01:36:48 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-02-23 01:36:48 +0900 |
| commit | 647c6ea21baa28192e5c4339ed4cdf83e994036e (patch) | |
| tree | f1c0e5c757bb24c0be905951c86ba701f18cddee /command | |
| parent | 416d93e8802dc4f42ce814edf874c79e2682af58 (diff) | |
command: hide internal commands
This marks commands as internal via a magic usage string.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'command')
| -rw-r--r-- | command/command.go | 3 | ||||
| -rw-r--r-- | command/help.go | 6 | ||||
| -rw-r--r-- | command/parse_test.go | 1 |
3 files changed, 8 insertions, 2 deletions
diff --git a/command/command.go b/command/command.go index 525dde3d..eeec135d 100644 --- a/command/command.go +++ b/command/command.go @@ -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 diff --git a/command/help.go b/command/help.go index a3735406..cb22ce50 100644 --- a/command/help.go +++ b/command/help.go @@ -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) } diff --git a/command/parse_test.go b/command/parse_test.go index 3174dccc..4bb924f4 100644 --- a/command/parse_test.go +++ b/command/parse_test.go @@ -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 { |
