本文整理汇总了Golang中launchpad/net/gnuflag.FlagSet.VisitAll方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.VisitAll方法的具体用法?Golang FlagSet.VisitAll怎么用?Golang FlagSet.VisitAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/gnuflag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.VisitAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Help
// Help renders i's content, along with documentation for any
// flags defined in f. It calls f.SetOutput(ioutil.Discard).
func (i *Info) Help(f *gnuflag.FlagSet) []byte {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "usage: %s", i.Name)
hasOptions := false
f.VisitAll(func(f *gnuflag.Flag) { hasOptions = true })
if hasOptions {
fmt.Fprintf(buf, " [options]")
}
if i.Args != "" {
fmt.Fprintf(buf, " %s", i.Args)
}
fmt.Fprintf(buf, "\n")
if i.Purpose != "" {
fmt.Fprintf(buf, "purpose: %s\n", i.Purpose)
}
if hasOptions {
fmt.Fprintf(buf, "\noptions:\n")
f.SetOutput(buf)
f.PrintDefaults()
}
f.SetOutput(ioutil.Discard)
if i.Doc != "" {
fmt.Fprintf(buf, "\n%s\n", strings.TrimSpace(i.Doc))
}
if len(i.Aliases) > 0 {
fmt.Fprintf(buf, "\naliases: %s\n", strings.Join(i.Aliases, ", "))
}
return buf.Bytes()
}
示例2: SetCommonFlags
// SetCommonFlags creates a new "commonflags" flagset, whose
// flags are shared with the argument f; this enables us to
// add non-global flags to f, which do not carry into subcommands.
func (c *SuperCommand) SetCommonFlags(f *gnuflag.FlagSet) {
if c.Log != nil {
c.Log.AddFlags(f)
}
f.BoolVar(&c.showHelp, "h", false, helpPurpose)
f.BoolVar(&c.showHelp, "help", false, "")
// In the case where we are providing the basis for a plugin,
// plugins are required to support the --description argument.
// The Purpose attribute will be printed (if defined), allowing
// plugins to provide a sensible line of text for 'juju help plugins'.
f.BoolVar(&c.showDescription, "description", false, "")
c.commonflags = gnuflag.NewFlagSet(c.Info().Name, gnuflag.ContinueOnError)
c.commonflags.SetOutput(ioutil.Discard)
f.VisitAll(func(flag *gnuflag.Flag) {
c.commonflags.Var(flag.Value, flag.Name, flag.Usage)
})
}
示例3: MergeFlagSet
func MergeFlagSet(fs1, fs2 *gnuflag.FlagSet) *gnuflag.FlagSet {
fs2.VisitAll(func(flag *gnuflag.Flag) {
fs1.Var(flag.Value, flag.Name, flag.Usage)
})
return fs1
}