Repository navigation
Order of processing #2521
|
I am using v3. I'm having an issue with global flags not being validated before a sub-command's I have a global flag, $ a2m -D 7 However, in the $ a2m -D 7 show conf a Why isn't the Do I have to explicitly invoke the application Thanks in advance... |
Replies: 2 comments
|
The root command's For this range check, put the validation on your root &cli.IntFlag{
Name: "debug",
Aliases: []string{"D"},
Value: 0,
Action: func(ctx context.Context, cmd *cli.Command, value int) error {
if value < 0 || value > 5 {
return fmt.Errorf("--debug must be in the range 0..5")
}
return nil
},
},This uses I checked this with v3.14.0 using a root command with nested Flag actions run when the flag is set. If you need validation or setup on every invocation, including when the default is used, put that in the root command's Reference: v3 flag actions. |
|
Thank you so much! I suspected that I was jaded by Ruby Thank you again! |
The root command's
Actionhandles running the root command itself. When you selectshow conf, the handler that runs is that subcommand'sAction; the parentActionfunctions aren't called along the way.For this range check, put the validation on your root
IntFlag:This uses
contextandfmtfrom the standard library. An error returned by the flag action stops execution before the selected command'sA…