fix: restore grouped command help forms
This commit is contained in:
parent
ecdbe91adf
commit
d98475c3d2
@ -98,9 +98,21 @@ func normalizeKongHelpArgs(args []string) []string {
|
||||
next = append(next, "--help")
|
||||
return next
|
||||
}
|
||||
if isKongCommandGroup(args[0]) && (len(args) == 1 || args[1] == "help") {
|
||||
return []string{args[0], "--help"}
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func isKongCommandGroup(command string) bool {
|
||||
switch command {
|
||||
case "actions", "admin", "cache", "config", "desktop", "image", "machine", "pool":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type initKongCmd struct {
|
||||
Args []string `arg:"" optional:""`
|
||||
}
|
||||
|
||||
@ -84,14 +84,20 @@ func TestSubcommandHelpExitsZero(t *testing.T) {
|
||||
func TestGroupedCommandHelpExitsZero(t *testing.T) {
|
||||
for _, command := range []string{"actions", "admin", "cache", "config", "desktop", "pool", "machine"} {
|
||||
t.Run(command, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
app := App{Stdout: &stdout, Stderr: &bytes.Buffer{}}
|
||||
err := app.Run(context.Background(), []string{command, "--help"})
|
||||
if err != nil {
|
||||
t.Fatalf("%s --help error=%v, want nil", command, err)
|
||||
}
|
||||
if !strings.Contains(stdout.String(), "Usage:") {
|
||||
t.Fatalf("%s --help output missing usage: %s", command, stdout.String())
|
||||
for _, args := range [][]string{
|
||||
{command, "--help"},
|
||||
{command, "help"},
|
||||
{command},
|
||||
} {
|
||||
var stdout bytes.Buffer
|
||||
app := App{Stdout: &stdout, Stderr: &bytes.Buffer{}}
|
||||
err := app.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatalf("%v error=%v, want nil", args, err)
|
||||
}
|
||||
if !strings.Contains(stdout.String(), "Usage:") {
|
||||
t.Fatalf("%v output missing usage: %s", args, stdout.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user