urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
22.21k stars 1.7k forks source link

Wrong help output when a Command has "HideHelpCommand=true" but no defined subcommands #1879

Open fsufitch opened 6 months ago

fsufitch commented 6 months ago

My urfave/cli version is

v2.27.1

Checklist

Dependency Management

Describe the bug

When HideHelpCommand is set to true on a command with no subcommands, the help text output by [...] mycmd --help imples there are subcommands, when in fact there are none. By comparison, the text output by [...] help mycmd is correct, though!

To reproduce

package main

import (
    "fmt"

    "github.com/urfave/cli/v2"
)

func main() {
    app := &cli.App{Commands: []*cli.Command{{
        Name:            "foo",
        HideHelpCommand: true, // <--- problem is here
    }}}

    app.Run([]string{"CMD", "help", "foo"})

    fmt.Print("\n\n========================================\n\n")

    app.Run([]string{"CMD", "foo", "--help"})
}

Observed behavior

The former execution presents the usage:

play foo [command options] [arguments...]

While the latter presents the (incorrect) usage:

play foo command [command options]

Expected behavior

The two outputs should match. The help calls are equivalent, and the latter output is misleading.

Additional context

Playground of the broken code: https://go.dev/play/p/kCuTCXk3Uxg

Run go version and paste its output here

N/A (Go 1.22 in the Go Playground)

Run go env and paste its output here

N/A (Go 1.22 in the Go Playground)