本文整理汇总了Golang中flag.FlagSet.IntVar方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.IntVar方法的具体用法?Golang FlagSet.IntVar怎么用?Golang FlagSet.IntVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.IntVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Register
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
f.StringVar(&cmd.spec.VswitchName, "vswitch", "", "vSwitch Name")
f.IntVar(&cmd.spec.VlanId, "vlan", 0, "VLAN ID")
}
示例2: Register
func (cmd *change) Register(f *flag.FlagSet) {
f.Int64Var(&cmd.MemoryMB, "m", 0, "Size in MB of memory")
f.IntVar(&cmd.NumCPUs, "c", 0, "Number of CPUs")
f.StringVar(&cmd.GuestId, "g", "", "Guest OS")
f.StringVar(&cmd.Name, "name", "", "Display name")
f.Var(&cmd.extraConfig, "e", "ExtraConfig. <key>=<value>")
}
示例3: Register
func (cmd *enter) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
f.IntVar(&cmd.timeout, "timeout", 0, "Timeout")
f.BoolVar(&cmd.evacuate, "evacuate", false, "Evacuate powered off VMs")
}
示例4: flagPointer
func flagPointer(incoming reflect.Value, data *flag.FlagSet) error {
if incoming.Type().Kind() == reflect.Ptr {
return flagPointer(incoming.Elem(), data)
}
for i := 0; i < incoming.NumField(); i++ {
field := incoming.Field(i)
fieldType := incoming.Type().Field(i)
if it := fieldType.Tag.Get("flag"); it != "" {
/* Register the flag */
switch field.Type().Kind() {
case reflect.Int:
data.IntVar(
(*int)(unsafe.Pointer(field.Addr().Pointer())),
it,
int(field.Int()),
fieldType.Tag.Get("description"),
)
continue
case reflect.String:
data.StringVar(
(*string)(unsafe.Pointer(field.Addr().Pointer())),
it,
field.String(),
fieldType.Tag.Get("description"),
)
continue
default:
return fmt.Errorf("Unknown type: %s", field.Type().Kind())
}
}
}
return nil
}
示例5: Register
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
cmd.ClientFlag.Register(ctx, f)
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
cmd.DatastoreFlag.Register(ctx, f)
cmd.ResourcePoolFlag, ctx = flags.NewResourcePoolFlag(ctx)
cmd.ResourcePoolFlag.Register(ctx, f)
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
cmd.NetworkFlag, ctx = flags.NewNetworkFlag(ctx)
cmd.NetworkFlag.Register(ctx, f)
f.IntVar(&cmd.memory, "m", 1024, "Size in MB of memory")
f.IntVar(&cmd.cpus, "c", 1, "Number of CPUs")
f.StringVar(&cmd.guestID, "g", "otherGuest", "Guest OS")
f.BoolVar(&cmd.link, "link", true, "Link specified disk")
f.BoolVar(&cmd.on, "on", true, "Power on VM. Default is true if -disk argument is given.")
f.BoolVar(&cmd.force, "force", false, "Create VM if vmx already exists")
f.StringVar(&cmd.controller, "disk.controller", "scsi", "Disk controller type")
f.StringVar(&cmd.iso, "iso", "", "ISO path")
cmd.isoDatastoreFlag, ctx = flags.NewCustomDatastoreFlag(ctx)
f.StringVar(&cmd.isoDatastoreFlag.Name, "iso-datastore", "", "Datastore for ISO file")
f.StringVar(&cmd.disk, "disk", "", "Disk path")
cmd.diskDatastoreFlag, ctx = flags.NewCustomDatastoreFlag(ctx)
f.StringVar(&cmd.diskDatastoreFlag.Name, "disk-datastore", "", "Datastore for disk file")
}
示例6: RegisterFlags
// RegisterFlags creates flag on the provided flagset. It can be used to
// declare flags on the main flagset instance using flag.CommandLine as a
// parameter.
func (s *Settings) RegisterFlags(fs *flag.FlagSet) {
prefix := s.FlagPrefix
fs.StringVar(&s.Host, prefix+"host", s.Host, "Host on which to listen on.")
fs.IntVar(&s.Port, prefix+"port", s.Port, "Port stdweb will listen on to program output.")
fs.StringVar(&s.KeyFile, prefix+"keyfile", s.KeyFile, "File to store the auth cookie between sessions.")
fs.StringVar(&s.StaticDir, prefix+"static_dir", s.StaticDir, "Load static content from this directory instead of using built-in data.")
}
示例7: ApplyWithError
// ApplyWithError populates the flag given the flag set and environment
func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
envVar = strings.TrimSpace(envVar)
if envVal, ok := syscall.Getenv(envVar); ok {
envValInt, err := strconv.ParseInt(envVal, 0, 64)
if err != nil {
return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
}
f.Value = int(envValInt)
break
}
}
}
eachName(f.Name, func(name string) {
if f.Destination != nil {
set.IntVar(f.Destination, name, f.Value, f.Usage)
return
}
set.Int(name, f.Value, f.Usage)
})
return nil
}
示例8: Run
func Run(flag *flag.FlagSet) Command {
query := crank.StartQuery{}
flag.IntVar(&query.StopTimeout, "stop", -1, "Stop timeout in seconds")
flag.IntVar(&query.StartTimeout, "start", -1, "Start timeout in seconds")
flag.IntVar(&query.Pid, "pid", 0, "Only if the current pid matches")
flag.BoolVar(&query.Wait, "wait", false, "Wait for a result")
flag.StringVar(&query.Cwd, "cwd", "", "Working directory")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s run [opts] -- [command ...args]:\n", os.Args[0])
flag.PrintDefaults()
}
return func(client *rpc.Client) (err error) {
var reply crank.StartReply
// Command and args are passed after
if flag.NArg() > 0 {
query.Command = flag.Args()
}
if err = client.Call("crank.Run", &query, &reply); err != nil {
fmt.Println("Failed to start:", err)
return
}
if reply.Code > 0 {
fmt.Println("Exited with code:", reply.Code)
return
}
fmt.Println("Started successfully")
return
}
}
示例9: FlagsForClient
func FlagsForClient(ccfg *ClientConfig, flagset *flag.FlagSet) {
flagset.DurationVar(&ccfg.IdleTimeout, "timeout", DefaultIdleTimeout, "amount of idle time before timeout")
flagset.IntVar(&ccfg.IdleConnectionsToInstance, "maxidle", DefaultIdleConnectionsToInstance, "maximum number of idle connections to a particular instance")
flagset.IntVar(&ccfg.MaxConnectionsToInstance, "maxconns", DefaultMaxConnectionsToInstance, "maximum number of concurrent connections to a particular instance")
flagset.StringVar(&ccfg.Region, "region", GetDefaultEnvVar("SKYNET_REGION", DefaultRegion), "region client is located in")
flagset.StringVar(&ccfg.Host, "host", GetDefaultEnvVar("SKYNET_HOST", DefaultRegion), "host client is located in")
}
示例10: Register
func (cmd *logs) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
f.IntVar(&cmd.Max, "n", 25, "Output the last N logs")
f.StringVar(&cmd.Key, "log", "", "Log file key")
}
示例11: Setup
// Setup the parameters with the command line flags in args.
func (pool *Pool) Setup(fs *flag.FlagSet, args []string) error {
fs.IntVar(&pool.Capacity, "capacity", pool.Capacity, "max parallel sandboxes")
fs.StringVar(&pool.UmlPath, "uml", pool.UmlPath, "path to the UML executable")
fs.StringVar(&pool.EnvDir, "envdir", pool.EnvDir, "environments directory")
fs.StringVar(&pool.TasksDir, "tasksdir", pool.TasksDir, "tasks directory")
return fs.Parse(args)
}
示例12: Flags
func Flags(flagSet *flag.FlagSet, prefix string, includeParallelFlags bool) {
prefix = processPrefix(prefix)
flagSet.Int64Var(&(GinkgoConfig.RandomSeed), prefix+"seed", time.Now().Unix(), "The seed used to randomize the spec suite.")
flagSet.BoolVar(&(GinkgoConfig.RandomizeAllSpecs), prefix+"randomizeAllSpecs", false, "If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe/Context groups.")
flagSet.BoolVar(&(GinkgoConfig.SkipMeasurements), prefix+"skipMeasurements", false, "If set, ginkgo will skip any measurement specs.")
flagSet.BoolVar(&(GinkgoConfig.FailOnPending), prefix+"failOnPending", false, "If set, ginkgo will mark the test suite as failed if any specs are pending.")
flagSet.BoolVar(&(GinkgoConfig.FailFast), prefix+"failFast", false, "If set, ginkgo will stop running a test suite after a failure occurs.")
flagSet.BoolVar(&(GinkgoConfig.DryRun), prefix+"dryRun", false, "If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.")
flagSet.StringVar(&(GinkgoConfig.FocusString), prefix+"focus", "", "If set, ginkgo will only run specs that match this regular expression.")
flagSet.StringVar(&(GinkgoConfig.SkipString), prefix+"skip", "", "If set, ginkgo will only run specs that do not match this regular expression.")
flagSet.BoolVar(&(GinkgoConfig.EmitSpecProgress), prefix+"progress", false, "If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.")
if includeParallelFlags {
flagSet.IntVar(&(GinkgoConfig.ParallelNode), prefix+"parallel.node", 1, "This worker node's (one-indexed) node number. For running specs in parallel.")
flagSet.IntVar(&(GinkgoConfig.ParallelTotal), prefix+"parallel.total", 1, "The total number of worker nodes. For running specs in parallel.")
flagSet.StringVar(&(GinkgoConfig.SyncHost), prefix+"parallel.synchost", "", "The address for the server that will synchronize the running nodes.")
flagSet.StringVar(&(GinkgoConfig.StreamHost), prefix+"parallel.streamhost", "", "The address for the server that the running nodes should stream data to.")
}
flagSet.BoolVar(&(DefaultReporterConfig.NoColor), prefix+"noColor", false, "If set, suppress color output in default reporter.")
flagSet.Float64Var(&(DefaultReporterConfig.SlowSpecThreshold), prefix+"slowSpecThreshold", 5.0, "(in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter (default: 5 seconds).")
flagSet.BoolVar(&(DefaultReporterConfig.NoisyPendings), prefix+"noisyPendings", true, "If set, default reporter will shout about pending tests.")
flagSet.BoolVar(&(DefaultReporterConfig.Verbose), prefix+"v", false, "If set, default reporter print out all specs as they begin.")
flagSet.BoolVar(&(DefaultReporterConfig.Succinct), prefix+"succinct", false, "If set, default reporter prints out a very succinct report")
flagSet.BoolVar(&(DefaultReporterConfig.FullTrace), prefix+"trace", false, "If set, default reporter prints out the full stack trace when a failure occurs")
}
示例13: RegisterFlags
func (cmd *instanceDelete) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cmd.list.hostname, "hostname", "", "Filters instances by hostname.")
f.StringVar(&cmd.list.env, "env", "", "Filters instances by environment.")
f.IntVar(&cmd.list.id, "id", 0, "Filters instances by id.")
f.BoolVar(&cmd.dry, "dry-run", false, "Dry run.")
cmd.list.entries = true
}
示例14: FlagByType
// FlagByType sets the appropriate flag for its type.
func FlagByType(fs *flag.FlagSet, structName string, fval reflect.Value, ftype reflect.StructField) {
// Get a pointer; FlagSet needs a pointer to set the struct's field
if fval.Kind() == reflect.Ptr {
// Short-circuit
log.Printf("Skipping field %s: %s", ftype.Name, ftype.Type.String())
return
}
//log.Printf("Getting pointer to %s", ftype.Name)
fval = fval.Addr()
flagName := NameToFlag(ftype.Name)
flagHelp := fmt.Sprintf("%s:%s", structName, ftype.Name)
log.Printf("Converting %s => %s", ftype.Name, flagName)
//log.Printf("Switching on type %s...", ftype.Type.String())
switch fval := fval.Interface().(type) {
case *int:
fs.IntVar(fval, flagName, 0, flagHelp)
case *float64:
fs.Float64Var(fval, flagName, 0.0, flagHelp)
case *string:
fs.StringVar(fval, flagName, "", flagHelp)
case *bool:
fs.BoolVar(fval, flagName, false, flagHelp)
case *time.Time:
t := (*time.Time)(fval) // Get a *time.Time pointer to fval
*t = time.Now() // Set a default of time.Now()
fs.Var((*TimeFlag)(fval), flagName, flagHelp)
default:
log.Printf("unexpected type %s\n", ftype.Type.String())
}
}
示例15: Register
func (cmd *tail) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
cmd.DatastoreFlag.Register(ctx, f)
f.Int64Var(&cmd.count, "c", -1, "Output the last NUM bytes")
f.IntVar(&cmd.lines, "n", 10, "Output the last NUM lines")
f.BoolVar(&cmd.follow, "f", false, "Output appended data as the file grows")
}