本文整理汇总了Golang中github.com/spf13/pflag.FlagSet.IntVarP方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.IntVarP方法的具体用法?Golang FlagSet.IntVarP怎么用?Golang FlagSet.IntVarP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/pflag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.IntVarP方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: registerFlagInt
func registerFlagInt(t reflect.Kind, fs *pflag.FlagSet, field interface{}, parts []string, vt int64, desc string) {
switch t {
case reflect.Int:
if len(parts) == 1 {
fs.IntVar(field.(*int), parts[0], int(vt), desc)
} else {
fs.IntVarP(field.(*int), parts[0], parts[1], int(vt), desc)
}
case reflect.Int8:
if len(parts) == 1 {
fs.Int8Var(field.(*int8), parts[0], int8(vt), desc)
} else {
fs.Int8VarP(field.(*int8), parts[0], parts[1], int8(vt), desc)
}
case reflect.Int32:
if len(parts) == 1 {
fs.Int32Var(field.(*int32), parts[0], int32(vt), desc)
} else {
fs.Int32VarP(field.(*int32), parts[0], parts[1], int32(vt), desc)
}
case reflect.Int64:
if len(parts) == 1 {
fs.Int64Var(field.(*int64), parts[0], int64(vt), desc)
} else {
fs.Int64VarP(field.(*int64), parts[0], parts[1], int64(vt), desc)
}
}
}
示例2: BindIntFlag
// BindIntFlag binds a flag that expects an integer value.
func (i FlagInfo) BindIntFlag(flags *pflag.FlagSet, target *int) {
// assume flags with no longname are not desired
if len(i.LongName) > 0 {
// try to parse Default as an int. If it fails, assume 0
intVal, _ := strconv.ParseInt(i.Default, 10, 0)
flags.IntVarP(target, i.LongName, i.ShortName, int(intVal), i.Description)
}
}
示例3: intFlag
func intFlag(f *pflag.FlagSet, valPtr *int, flagInfo cliflags.FlagInfo, defaultVal int) {
if flagInfo.Shorthand == "" {
f.IntVar(valPtr, flagInfo.Name, defaultVal, makeUsageString(flagInfo))
} else {
f.IntVarP(valPtr, flagInfo.Name, flagInfo.Shorthand, defaultVal, makeUsageString(flagInfo))
}
setFlagFromEnv(f, flagInfo)
}
示例4: AddFlags
func (conf *BasicConfig) AddFlags(flags *flag.FlagSet) {
flags.Int64VarP(&conf.NumRequests, "numrequests", "n", 10000, "Number of requests.")
flags.IntVarP(&conf.Concurrency, "concurrency", "c", 100, "Number of concurrent workers.")
flags.StringVarP(&conf.Cluster, "cluster", "", "", "Peer nodes to use, if none, use this process.")
}
示例5: intVarP
func (c *Config) intVarP(fset *flag.FlagSet, name string, aof *int) *flag.Flag {
i := keys[name]
fset.IntVarP(aof, name, i.Shorthand, c.Viper.GetInt(name), i.Description)
return fset.Lookup(name)
}