cli
cli copied to clipboard
Strict flag lookup
Checklist
- [x] Are you running the latest v2 release? The list of releases is here.
- [x] Did you check the manual for your release? The v2 manual is here.
- [x] Did you perform a search about this feature? Here's the Github guide about searching.
What problem does this solve?
I've had several cases where I've made a typo when accessing a flag value via the context.
Solution description
I'd like the library to panic if I access an undefined flag.
func main() {
app := &cli.App{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "foo",
},
},
Action: func(c *cli.Context) error {
// I want this to panic
_ = c.String("bar")
return nil
},
}
app.Run([]string{"test"})
}
@icholy you may want to consider using the recently-added (by @toaster 🙇🏼) ability to get the value directly from a given flag
I'd much prefer to keep my existing code and just enable some type of "strict mode" flag.
@icholy This would be nice, are you willing to submit a PR ?
@dearchap if you want to, go for it. Edit see the linked pr.
Fixed. .