From 4656f88be2b144552af0ba30017fa9ae582604a0 Mon Sep 17 00:00:00 2001 From: Mateusz Jakubiec Date: Mon, 25 Jul 2022 10:54:26 +0200 Subject: [PATCH] DXE-1337 Fix help for alias commands --- pkg/apphelp/help_command.go | 12 ++++++++++ pkg/apphelp/help_command_test.go | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/pkg/apphelp/help_command.go b/pkg/apphelp/help_command.go index f61d4a2..d9a462d 100644 --- a/pkg/apphelp/help_command.go +++ b/pkg/apphelp/help_command.go @@ -72,7 +72,19 @@ func isBuiltinCommand(c *cli.Context, cmdName string) bool { if cmd.Name == cmdName { return true } + if contains(cmd.Aliases, cmdName) { + return true + } } return false } + +func contains(slc []string, e string) bool { + for _, s := range slc { + if s == e { + return true + } + } + return false +} diff --git a/pkg/apphelp/help_command_test.go b/pkg/apphelp/help_command_test.go index 7feb122..2f23df4 100644 --- a/pkg/apphelp/help_command_test.go +++ b/pkg/apphelp/help_command_test.go @@ -76,6 +76,40 @@ Command Flags: --test-flag this is a test flag (default: false) --help, -h show help (default: false) +Global Flags: + --edgerc value, -e value edgerc config path passed to executed commands, defaults to ~/.edgerc + --section value, -s value edgerc section name passed to executed commands, defaults to 'default' +`, binarySuffix, binarySuffix), + }, + "help for specific command alias": { + args: []string{"test-alias"}, + cmd: &cli.Command{ + Name: "test", + Aliases: []string{"test-alias"}, + Description: "test command", + Category: "", + ArgsUsage: " ", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "test-flag", + Usage: "this is a test flag", + }, + }, + }, + expectedOutput: fmt.Sprintf(` +Name: + apphelp.test%s test + +Usage: + apphelp.test%s [global flags] test [command flags] + +Description: + test command + +Command Flags: + --test-flag this is a test flag (default: false) + --help, -h show help (default: false) + Global Flags: --edgerc value, -e value edgerc config path passed to executed commands, defaults to ~/.edgerc --section value, -s value edgerc section name passed to executed commands, defaults to 'default' @@ -245,3 +279,7 @@ Command Flags: } } } + +//func TestIsBuiltinCommand(t *testing.T) { +// +//}