cobra icon indicating copy to clipboard operation
cobra copied to clipboard

cobra.Command.Flags().Lookup() should return an error for flags that don't exist

Open TobiOkanlawon opened this issue 1 year ago • 2 comments

TobiOkanlawon avatar Oct 21 '23 19:10 TobiOkanlawon

I think that the code would be more robust if it handled the case where a flag lookup with an error

TobiOkanlawon avatar Oct 21 '23 19:10 TobiOkanlawon

Lookup() returns nil when the flag does not exist. What scenario would an error improve?

That being said, the Lookup() function is not implemented in Cobra but in spf13/pflag: https://github.com/spf13/pflag/blob/d5e0c0615acee7028e1e2740a11102313be88de1/flag.go#L355

marckhouzam avatar Oct 22 '23 00:10 marckhouzam