我在 a 中添加了以下标志cobra.Cmd
myCmd.PersistentFlags().StringP(applicationLongFlag, applicationShortFlag, applicationDefaultValue, applicationFlagHelpMsg)
在哪里
applicationLongFlag = "application"
applicationShortFlag = "a"
applicationDefaultValue = ""
applicationFlagHelpMsg = "The application name"
这可以按预期工作,但是当尝试根据需要制作上述标志时,该过程会失败
if err := myCmd.MarkFlagRequired(applicationShortFlag); err != nil {
return errors.Wrapf(err, "error marking %s as required flag", applicationShortFlag)
}
error marking a as required flag: no such flag -a
-a
/--application
按预期工作,它也打印在我的帮助中
▶ go run myprog.go mycommand --help
Usage:
myprog.go mycommand [flags]
Flags:
-a, --application string The application name
为什么没有按要求设置?