My urfave/cli version is
v3.3.2
Checklist
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
My urfave/cli version is
v3.3.2
Checklist
Describe the bug
The
--helpargument causes an error when specified in a command with arguments.To reproduce
Observed behavior
Both these commands work:
But when I specify one of the command's arguments, it raises an error:
Expected behavior
I'm not sure if that's intentional behavior, but with
nanofor example (just a random command), I can specify--helpboth before and after an argument.Run
go versionand paste its output here