From f306ae1529caeb89f707932b499b2b455367f9fe Mon Sep 17 00:00:00 2001 From: Joe Schmitt Date: Fri, 12 Feb 2021 11:51:30 -0500 Subject: [PATCH] Add aliases to tree help output --- help.go | 3 +++ help_test.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/help.go b/help.go index 2594946..f08f1a1 100644 --- a/help.go +++ b/help.go @@ -474,6 +474,9 @@ func (h *HelpOptions) CommandTree(node *Node, prefix string) (rows [][2]string) switch node.Type { default: nodeName += prefix + node.Name + if len(node.Aliases) != 0 { + nodeName += fmt.Sprintf(" (%s)", strings.Join(node.Aliases, ",")) + } case ArgumentNode: nodeName += prefix + "<" + node.Name + ">" } diff --git a/help_test.go b/help_test.go index c7d5fe0..0f0f2cb 100644 --- a/help_test.go +++ b/help_test.go @@ -245,13 +245,13 @@ func TestHelpTree(t *testing.T) { Other struct { Other string `arg help:"other arg"` } `arg help:"subcommand other"` - } `cmd help:"subcommand one" group:"Group A"` // Groups are ignored in trees + } `cmd help:"subcommand one" group:"Group A" aliases:"un,uno"` // Groups are ignored in trees Two struct { Three threeArg `arg help:"Sub-sub-arg."` Four struct { - } `cmd help:"Sub-sub-command."` + } `cmd help:"Sub-sub-command." aliases:"for,fore"` } `cmd help:"Another subcommand."` } @@ -285,14 +285,14 @@ Flags: -h, --help Show context-sensitive help. Commands: - one subcommand one - - thing subcommand thing - - argument - - subcommand other + one (un,uno) subcommand one + - thing subcommand thing + - argument + - subcommand other - two Another subcommand. - - Sub-sub-arg. - - four Sub-sub-command. + two Another subcommand. + - Sub-sub-arg. + - four (for,fore) Sub-sub-command. Run "test-app --help" for more information on a command. `