Skip to content

Commit

Permalink
DXE-1337 Fix help subcommand for alias commands
Browse files Browse the repository at this point in the history
  • Loading branch information
majakubiec committed Jul 25, 2022
2 parents 375aced + 4656f88 commit 6752281
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/apphelp/help_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
38 changes: 38 additions & 0 deletions pkg/apphelp/help_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<arg1> <arg2>",
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] <arg1> <arg2>
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'
Expand Down Expand Up @@ -245,3 +279,7 @@ Command Flags:
}
}
}

//func TestIsBuiltinCommand(t *testing.T) {
//
//}

0 comments on commit 6752281

Please sign in to comment.