-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
my urfave/cli version is
master branch
Checklist
- Are you running the latest v2 release? The list of releases is here.
- Did you check the manual for your release? The v2 manual is here
- Did you perform a search about this problem? Here's the Github guide about searching.
Dependency Management
- My project is using go modules.
- My project is using vendoring.
- My project is automatically downloading the latest version.
- I am unsure of what my dependency management setup is.
Describe the bug
Setting Required
field to true
in Flags* will not worked while the Name field in flag only contains only one character.
To reproduce
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
&cli.StringFlag{Name: "c", Value: "config.yaml", Usage: "specify config file", Required: true},
}
app.Action = func(c *cli.Context) error {
fmt.Println(c.String("c"))
return nil
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
}
}
Observed behavior
When specified the Name
field to "c", and run program will exit normally with a config.yaml
output. When I Changed Name
field to "conf" program exit with help message and a Required flag "conf" not set
output which is as expected.
It seems the checkRequiredFlags
function in https://github.com/urfave/cli/blob/master/context.go#L256 filtered the key with length 1.
Expected behavior
I Want to know whether this behavior designed deliberately or not? If is, what's the purpose and can we clarify in the doc? If not, shall I correct this?
What I expect is Name field with only one character in flag should also work with checkRequiredFlags
Want to fix this yourself?
yes