本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/spf13/pflag.FlagSet类的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet类的具体用法?Golang FlagSet怎么用?Golang FlagSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlagSet类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: isBooleanFlag
// Test if the named flag is a boolean flag.
func isBooleanFlag(name string, f *flag.FlagSet) bool {
flag := f.Lookup(name)
if flag == nil {
return false
}
return flag.Value.Type() == "bool"
}
开发者ID:matomesc,项目名称:rkt,代码行数:8,代码来源:command.go
示例2: manPrintFlags
func manPrintFlags(out *bytes.Buffer, flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 || flag.Hidden {
return
}
format := ""
if len(flag.Shorthand) > 0 {
format = "**-%s**, **--%s**"
} else {
format = "%s**--%s**"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "["
}
if flag.Value.Type() == "string" {
// put quotes on the value
format = format + "=%q"
} else {
format = format + "=%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "]"
}
format = format + "\n\t%s\n\n"
fmt.Fprintf(out, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)
})
}
开发者ID:matomesc,项目名称:rkt,代码行数:27,代码来源:man_docs.go
示例3: rktFlagUsages
func rktFlagUsages(flagSet *pflag.FlagSet) string {
x := new(bytes.Buffer)
flagSet.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 || flag.Hidden {
return
}
format := ""
if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {
format = " -%s, --%s"
} else {
format = " %s --%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "["
}
if flag.Value.Type() == "string" {
// put quotes on the value
format = format + "=%q"
} else {
format = format + "=%s"
}
if len(flag.NoOptDefVal) > 0 {
format = format + "]"
}
format = format + "\t%s\n"
shorthand := flag.Shorthand
fmt.Fprintf(x, format, shorthand, flag.Name, flag.DefValue, flag.Usage)
})
return x.String()
}
开发者ID:matomesc,项目名称:rkt,代码行数:32,代码来源:help.go
示例4: isBooleanShortFlag
// Test if the named flag is a boolean flag.
func isBooleanShortFlag(name string, f *flag.FlagSet) bool {
result := false
f.VisitAll(func(f *flag.Flag) {
if f.Shorthand == name && f.Value.Type() == "bool" {
result = true
}
})
return result
}
开发者ID:matomesc,项目名称:rkt,代码行数:10,代码来源:command.go
示例5: InstallDeprecatedSkipVerify
func InstallDeprecatedSkipVerify(flagset *pflag.FlagSet, flags *SecFlags) {
sv := &skipVerify{
flags: flags,
}
svFlag := flagset.VarPF(sv, "insecure-skip-verify", "", "DEPRECATED")
svFlag.DefValue = "false"
svFlag.NoOptDefVal = "true"
svFlag.Hidden = true
svFlag.Deprecated = "please use --insecure-options."
}
开发者ID:matomesc,项目名称:rkt,代码行数:10,代码来源:skip_verify.go
示例6: parseApps
// parseApps looks through the args for support of per-app argument lists delimited with "--" and "---".
// Between per-app argument lists flags.Parse() is called using the supplied FlagSet.
// Anything not consumed by flags.Parse() and not found to be a per-app argument list is treated as an image.
// allowAppArgs controls whether "--" prefixed per-app arguments will be accepted or not.
func parseApps(al *apps.Apps, args []string, flags *pflag.FlagSet, allowAppArgs bool) error {
nAppsLastAppArgs := al.Count()
// valid args here may either be:
// not-"--"; flags handled by *flags or an image specifier
// "--"; app arguments begin
// "---"; conclude app arguments
// between "--" and "---" pairs anything is permitted.
inAppArgs := false
for i := 0; i < len(args); i++ {
a := args[i]
if inAppArgs {
switch a {
case "---":
// conclude this app's args
inAppArgs = false
default:
// keep appending to this app's args
app := al.Last()
app.Args = append(app.Args, a)
}
} else {
switch a {
case "--":
if !allowAppArgs {
return fmt.Errorf("app arguments unsupported")
}
// begin app's args
inAppArgs = true
// catch some likely mistakes
if nAppsLastAppArgs == al.Count() {
if al.Count() == 0 {
return fmt.Errorf("an image is required before any app arguments")
}
return fmt.Errorf("only one set of app arguments allowed per image")
}
nAppsLastAppArgs = al.Count()
case "---":
// ignore triple dashes since they aren't images
// TODO(vc): I don't think ignoring this is appropriate, probably should error; it implies malformed argv.
// "---" is not an image separator, it's an optional argument list terminator.
// encountering it outside of inAppArgs is likely to be "--" typoed
default:
// consume any potential inter-app flags
if err := flags.Parse(args[i:]); err != nil {
return err
}
nInterFlags := (len(args[i:]) - flags.NArg())
if nInterFlags > 0 {
// XXX(vc): flag.Parse() annoyingly consumes the "--", reclaim it here if necessary
if args[i+nInterFlags-1] == "--" {
nInterFlags--
}
// advance past what flags.Parse() consumed
i += nInterFlags - 1 // - 1 because of i++
} else {
// flags.Parse() didn't want this arg, treat as image
al.Create(a)
}
}
}
}
return al.Validate()
}
开发者ID:matomesc,项目名称:rkt,代码行数:72,代码来源:cli_apps.go
示例7: MarkFlagFilename
// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag in the flag set, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.
func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error {
return flags.SetAnnotation(name, BashCompFilenameExt, extensions)
}
开发者ID:matomesc,项目名称:rkt,代码行数:5,代码来源:bash_completions.go
示例8: MarkFlagRequired
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists.
func MarkFlagRequired(flags *pflag.FlagSet, name string) error {
return flags.SetAnnotation(name, BashCompOneRequiredFlag, []string{"true"})
}
开发者ID:matomesc,项目名称:rkt,代码行数:4,代码来源:bash_completions.go
示例9: addStage1ImageFlag
// addStage1ImageFlag adds a flag for specifying custom stage1 image
// path
func addStage1ImageFlag(flags *pflag.FlagSet) {
flags.String(stage1ImageFlagName, defaultStage1Image, stage1ImageFlagHelp())
}
开发者ID:ngorskig,项目名称:rkt,代码行数:5,代码来源:stage1hash.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/spf13/pflag.FlagSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论