-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
area/v3relates to / is being considered for v3relates to / is being considered for v3kind/bugdescribes or fixes a bugdescribes or fixes a bug
Description
My urfave/cli version is
v3.3.2
Checklist
- Are you running the latest v3 release? The list of releases is here.
- Did you check the manual for your release? The v3 manual is here
- 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
Metadata
Metadata
Assignees
Labels
area/v3relates to / is being considered for v3relates to / is being considered for v3kind/bugdescribes or fixes a bugdescribes or fixes a bug