本文整理汇总了Golang中github.com/docker/docker/pkg/mflag.FlagSet.Usage方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.Usage方法的具体用法?Golang FlagSet.Usage怎么用?Golang FlagSet.Usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/pkg/mflag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.Usage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseFlags
// ParseFlags is a utility function that adds a help flag if withHelp is true,
// calls cmd.Parse(args) and prints a relevant error message if there are
// incorrect number of arguments. It returns error only if error handling is
// set to ContinueOnError and parsing fails. If error handling is set to
// ExitOnError, it's safe to ignore the return value.
// TODO: move this to a better package than utils
func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
var help *bool
if withHelp {
help = cmd.Bool([]string{"#help", "-help"}, false, "Print usage")
}
if err := cmd.Parse(args); err != nil {
return err
}
if help != nil && *help {
cmd.Usage()
// just in case Usage does not exit
os.Exit(0)
}
if str := cmd.CheckArgs(); str != "" {
ReportError(cmd, str, withHelp)
}
return nil
}