Help fails when a command argument is specified
My urfave/cli version is
v3.3.2
Checklist
- [x] Are you running the latest v3 release? The list of releases is here.
- [x] Did you check the manual for your release? The v3 manual is here
- [x] Did you perform a search about this problem? Here's the GitHub guide about searching.
Describe the bug
The --help argument causes an error when specified in a command with arguments.
To reproduce
package main
import (
"context"
"fmt"
"os"
"github.com/urfave/cli/v3"
)
func main() {
app := &cli.Command{
Name: "My CLI",
Usage: "My Usage",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "profile",
Aliases: []string{"p"},
Usage: "Name of the profile to use",
Value: "default",
},
},
Commands: []*cli.Command{
{
Name: "command",
Arguments: []cli.Argument{
&cli.StringArg{
Name: "arg1",
UsageText: "ARG1",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Printf("My profile: %s\n", cmd.String("profile"))
fmt.Printf("My command: arg1=%s\n", cmd.StringArg("arg1"))
return nil
},
Usage: "Show the version of My CLI",
},
},
}
err := app.Run(context.Background(), os.Args)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
}
Observed behavior
Both these commands work:
$ go run ./cli-error command --help
...
$ go run ./cli-error command --profile dev --help
...
But when I specify one of the command's arguments, it raises an error:
$ go run ./cli-error command ciao --help
Error: No help topic for 'ciao'
exit status 1
$ go run ./cli-error command --help ciao
Error: No help topic for 'ciao'
exit status 1
Expected behavior
I'm not sure if that's intentional behavior, but with nano for example (just a random command), I can specify --help both before and after an argument.
$ nano ./poetry.lock --help
Usage: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]...
$ nano --help poetry.lock
Usage: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]..
$ nano --help
Usage: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]...
$ nano --help2
nano: unrecognized option '--help2'
Type 'nano -h' for a list of available options.
Run go version and paste its output here
$ go version
go version go1.23.3 darwin/arm64
I also think that specifying the --help flag should work regardless of it's position. This is also stated in the CLI Guidelines:
Ignore any other flags and arguments that are passed—you should be able to add -h to the end of anything and it should show help.
Thank you for your thoughtful and thorough issue @bigluck 💖 !