Add aliases to tree help output
This commit is contained in:
@@ -474,6 +474,9 @@ func (h *HelpOptions) CommandTree(node *Node, prefix string) (rows [][2]string)
|
|||||||
switch node.Type {
|
switch node.Type {
|
||||||
default:
|
default:
|
||||||
nodeName += prefix + node.Name
|
nodeName += prefix + node.Name
|
||||||
|
if len(node.Aliases) != 0 {
|
||||||
|
nodeName += fmt.Sprintf(" (%s)", strings.Join(node.Aliases, ","))
|
||||||
|
}
|
||||||
case ArgumentNode:
|
case ArgumentNode:
|
||||||
nodeName += prefix + "<" + node.Name + ">"
|
nodeName += prefix + "<" + node.Name + ">"
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -245,13 +245,13 @@ func TestHelpTree(t *testing.T) {
|
|||||||
Other struct {
|
Other struct {
|
||||||
Other string `arg help:"other arg"`
|
Other string `arg help:"other arg"`
|
||||||
} `arg help:"subcommand other"`
|
} `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 {
|
Two struct {
|
||||||
Three threeArg `arg help:"Sub-sub-arg."`
|
Three threeArg `arg help:"Sub-sub-arg."`
|
||||||
|
|
||||||
Four struct {
|
Four struct {
|
||||||
} `cmd help:"Sub-sub-command."`
|
} `cmd help:"Sub-sub-command." aliases:"for,fore"`
|
||||||
} `cmd help:"Another subcommand."`
|
} `cmd help:"Another subcommand."`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,14 +285,14 @@ Flags:
|
|||||||
-h, --help Show context-sensitive help.
|
-h, --help Show context-sensitive help.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
one subcommand one
|
one (un,uno) subcommand one
|
||||||
- thing subcommand thing
|
- thing subcommand thing
|
||||||
- <arg> argument
|
- <arg> argument
|
||||||
- <other> subcommand other
|
- <other> subcommand other
|
||||||
|
|
||||||
two Another subcommand.
|
two Another subcommand.
|
||||||
- <three> Sub-sub-arg.
|
- <three> Sub-sub-arg.
|
||||||
- four Sub-sub-command.
|
- four (for,fore) Sub-sub-command.
|
||||||
|
|
||||||
Run "test-app <command> --help" for more information on a command.
|
Run "test-app <command> --help" for more information on a command.
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user