My urfave/cli version is
** v2.25.3**
Checklist
Dependency Management
- My project is using go modules.
Describe the bug
Ordering of arguments and flags impact one another, causing a flag value to be set or unset depending on whether it comes before or after an argument. This can result in a silent error where the flag name is recognized but the value isn't set.
To reproduce
Using the flag example from https://cli.urfave.org/v2/examples/flags/ (copying below for ease of reference)
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lang",
Value: "english",
Usage: "language for the greeting",
},
},
Action: func(cCtx *cli.Context) error {
name := "Nefertiti"
if cCtx.NArg() > 0 {
name = cCtx.Args().Get(0)
}
if cCtx.String("lang") == "spanish" {
fmt.Println("Hola", name)
} else {
fmt.Println("Hello", name)
}
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
Observed behavior
# argument
$ ./example my-name
Hello my-name
# flag
$ ./example --lang spanish
Hola Nefertiti
# flag before argument
$ ./example --lang spanish my-name
Hola my-name
# argument before flag
$ ./example my-name --lang spanish
Hello my-name
Expected behavior
$ ./example my-name --lang spanish and ./example --lang spanish my-name should both set the --lang flag to the value spanish
Additional context
N/A
Want to fix this yourself?
We'd love to have more contributors on this project! If the fix for
this bug is easily explained and very small, feel free to create a
pull request for it.
Run go version and paste its output here
go version go1.20.4 darwin/arm64
Run go env and paste its output here
# paste `go env` output in here
My urfave/cli version is
** v2.25.3**
Checklist
Dependency Management
Describe the bug
Ordering of arguments and flags impact one another, causing a flag value to be set or unset depending on whether it comes before or after an argument. This can result in a silent error where the flag name is recognized but the value isn't set.
To reproduce
Using the flag example from https://cli.urfave.org/v2/examples/flags/ (copying below for ease of reference)
Observed behavior
Expected behavior
$ ./example my-name --lang spanishand./example --lang spanish my-nameshould both set the--langflag to the valuespanishAdditional context
N/A
Want to fix this yourself?
We'd love to have more contributors on this project! If the fix for
this bug is easily explained and very small, feel free to create a
pull request for it.
Run
go versionand paste its output hereRun
go envand paste its output here