本文整理匯總了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
}
}
}