Skip to content

Strict flag lookup #1408

@icholy

Description

@icholy

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"})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/featuredescribes a code enhancement / feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions