You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a little confused why ValidateRequiredFlags() and ValidateFlagGroups() are executed after PersistentRunE() and PreRunE() in the current implementation. IMO, PersistentRunE() and PreRunE() can be set and controlled by developers, and all pre-check provided by cobra framework should throw error as soon as possible.
Got it. Backward compatibility is really a key point.
Considering that if any error threw by RunE(), the program will print the usage. The easiest way for me to control the print of error or usage is to set SilenceErrors and SilenceUsage to true in PersistentRunE(#340 (comment)). PersistentRunE can be inherited by all subcommands, and cobra can help me validate argument and flags before their executions.
The problem is that ValidateRequiredFlags() and ValidateFlagGroups() executed after would not print any hints as I set SilenceErrors and SilenceUsage. I haven't found a good way. Maybe I should do some checks myself.
FWIW It makes sense to me that flag validation would happen a least after PersistentPreRun. That is where we can manipulate the flags if needed prior to validation. I use the PersistentPreRun hook to work around spf13/viper#397.
I'm a little confused why
ValidateRequiredFlags()
andValidateFlagGroups()
are executed afterPersistentRunE()
andPreRunE()
in the current implementation. IMO,PersistentRunE()
andPreRunE()
can be set and controlled by developers, and all pre-check provided bycobra
framework should throw error as soon as possible.cobra/command.go
Lines 913 to 937 in fd865a4
The text was updated successfully, but these errors were encountered: