Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict flag lookup #1408

Closed
3 tasks done
icholy opened this issue Jun 6, 2022 · 5 comments
Closed
3 tasks done

Strict flag lookup #1408

icholy opened this issue Jun 6, 2022 · 5 comments
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request

Comments

@icholy
Copy link
Contributor

icholy commented Jun 6, 2022

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 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 icholy added area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this labels Jun 6, 2022
@meatballhat
Copy link
Member

@icholy you may want to consider using the recently-added (by @toaster 🙇🏼) ability to get the value directly from a given flag

@meatballhat meatballhat added kind/feature describes a code enhancement / feature request and removed status/triage maintainers still need to look into this labels Jun 18, 2022
@icholy
Copy link
Contributor Author

icholy commented Jul 12, 2022

I'd much prefer to keep my existing code and just enable some type of "strict mode" flag.

@dearchap
Copy link
Contributor

dearchap commented Aug 1, 2022

@icholy This would be nice, are you willing to submit a PR ?

@icholy
Copy link
Contributor Author

icholy commented Aug 1, 2022

@dearchap if you want to, go for it. Edit see the linked pr.

@dearchap
Copy link
Contributor

Fixed. .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request
Projects
None yet
Development

No branches or pull requests

3 participants