cli icon indicating copy to clipboard operation
cli copied to clipboard

Is there an easy way to toggle the Required attribute of a cli.Flag ?

Open zhiqiangxu opened this issue 3 years ago • 2 comments

Now I have to create separate cli.Flag flag instances for Required and Optional, which is quite tedious:

// HeightFlag ...
var HeightFlag = cli.IntFlag{
	Name:     "height",
	Usage:    "specify height",
	Required: true,
}

// OptionalHeightFlag ...
var OptionalHeightFlag = cli.IntFlag{
	Name:  "height",
	Usage: "specify optional height",
}

zhiqiangxu avatar Jan 17 '22 07:01 zhiqiangxu

What about

OptionalHeightFlag := HeightFlag
OptionalHeightFlag.Required = False

Necoro avatar Jan 19 '22 21:01 Necoro

What about

OptionalHeightFlag := HeightFlag
OptionalHeightFlag.Required = False

It still requires 2 variables, if there is a method like ToggleRequired(), then only 1 is enough.

zhiqiangxu avatar Jan 19 '22 23:01 zhiqiangxu

Interface cannot be update to include these functions at this point. Please consider using v3x

dearchap avatar Sep 12 '22 00:09 dearchap