本文整理汇总了Golang中flag.FlagSet.Parsed方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.Parsed方法的具体用法?Golang FlagSet.Parsed怎么用?Golang FlagSet.Parsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.Parsed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runRemoveBeer
func runRemoveBeer(command string, flags *flag.FlagSet, id int, cellar *BeerCellar) {
if command == "remove" {
if flags.Parsed() {
cellar.RemoveBeer(id)
cellar.PrintCellar(&StdOutPrint{})
}
}
}
示例2: runListBeers
func runListBeers(command string, flags *flag.FlagSet, numBombers int, numSmall int, cellar *BeerCellar) {
if command == "list" {
if flags.Parsed() {
cellar.PrintBeers(numBombers, numSmall)
} else {
flags.PrintDefaults()
}
}
}
示例3: runSearch
func runSearch(command string, flags *flag.FlagSet, search string) {
if command == "search" {
if flags.Parsed() {
matches := Search(search)
for _, match := range matches {
fmt.Printf("%v: %v\n", match.name, match.id)
}
} else {
flags.PrintDefaults()
}
}
}
示例4: registerFlagStruct
// registerFlagStruct parse struct field, and register with flag set
func registerFlagStruct(i interface{}, fs *flag.FlagSet) error {
if fs.Parsed() {
return ErrFlagParsed
}
sf := structFields(i)
for _, fd := range sf {
field := fd.field
flagName := fd.tag.name
flagUsage := fd.tag.usage
fieldPtr := unsafe.Pointer(fd.value.UnsafeAddr())
switch field.Type.Kind() {
case reflect.Int:
fs.IntVar((*int)(fieldPtr), flagName, fd.tag.intValue(), flagUsage)
case reflect.Int64:
fs.Int64Var((*int64)(fieldPtr), flagName, fd.tag.int64Value(), flagUsage)
case reflect.Uint:
fs.UintVar((*uint)(fieldPtr), flagName, fd.tag.uintValue(), flagUsage)
case reflect.Uint64:
fs.Uint64Var((*uint64)(fieldPtr), flagName, fd.tag.uint64Value(), flagUsage)
case reflect.String:
fs.StringVar((*string)(fieldPtr), flagName, fd.tag.stringValue(), flagUsage)
case reflect.Bool:
fs.BoolVar((*bool)(fieldPtr), flagName, fd.tag.boolValue(), flagUsage)
case reflect.Float64:
fs.Float64Var((*float64)(fieldPtr), flagName, fd.tag.float64Value(), flagUsage)
default:
if !reflect.PtrTo(field.Type).Implements(flagValueType) {
return ErrUnsupportType
}
fieldValue := reflect.NewAt(field.Type, fieldPtr)
switch value := fieldValue.Interface().(type) {
case flag.Value:
fs.Var(value, flagName, flagUsage)
}
}
}
return nil
}
示例5: runSaveUntappd
func runSaveUntappd(command string, flags *flag.FlagSet, key string, secret string, cellar *BeerCellar) {
if command == "untappd" {
if flags.Parsed() {
cellar.SetUntappd(key, secret)
untappdKey = key
untappdSecret = secret
} else {
flags.PrintDefaults()
}
} else {
if cellar.untappdKey == "" {
//Set from environment variables
untappdKey = os.Getenv("CLIENTID")
untappdSecret = os.Getenv("CLIENTSECRET")
} else {
untappdKey = cellar.untappdKey
untappdSecret = cellar.untappdSecret
}
}
}