当前位置: 首页>>代码示例>>Golang>>正文


Golang FlagSet.BoolVar方法代码示例

本文整理汇总了Golang中flag.FlagSet.BoolVar方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.BoolVar方法的具体用法?Golang FlagSet.BoolVar怎么用?Golang FlagSet.BoolVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flag.FlagSet的用法示例。


在下文中一共展示了FlagSet.BoolVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Register

func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
	cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
	cmd.DatacenterFlag.Register(ctx, f)

	f.BoolVar(&cmd.Long, "l", false, "Long listing format")
	f.StringVar(&cmd.Type, "t", "", "Object type")
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:7,代码来源:command.go

示例2: RegisterFlags

// RegisterFlags sets the flags for the command - "team bootstrap <flags>".
func (cmd *TeamBootstrap) RegisterFlags(f *flag.FlagSet) {
	f.StringVar(&cmd.Provider, "p", "aws", "Team provider name.")
	f.StringVar(&cmd.Team, "team", "koding", "Team name.")
	f.StringVar(&cmd.Creds, "creds", "", "Comma-separated credential identifier list.")
	f.BoolVar(&cmd.Destroy, "del", false, "Destroy resources.")
	f.StringVar(&cmd.Username, "u", defaultUsername, "Username for the kloud request.")
}
开发者ID:koding,项目名称:koding,代码行数:8,代码来源:team.go

示例3: ApplyWithError

// ApplyWithError populates the flag given the flag set and environment
func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
	val := true
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				if envVal == "" {
					val = false
					break
				}

				envValBool, err := strconv.ParseBool(envVal)
				if err != nil {
					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
				}

				val = envValBool
				break
			}
		}
	}

	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.BoolVar(f.Destination, name, val, f.Usage)
			return
		}
		set.Bool(name, val, f.Usage)
	})

	return nil
}
开发者ID:octoblu,项目名称:go-go,代码行数:33,代码来源:flag.go

示例4: DefineFlags

func (cmd *add) DefineFlags(fs *flag.FlagSet) {
	fs.BoolVar(&cmd.json, "json", false, "Output result as JSON")
	fs.StringVar(&cmd.uri, "uri", "", "Drain URI (eg: udp://logs.loggly.com:12345)")
	fs.Var(&cmd.filters, "filter", "Message filter")
	cmd.params = make(map[string]string)
	fs.Var(&cmd.params, "o", "Drain options (eg: -o 'limit=100' or -o 'format={{.Text}}'")
}
开发者ID:way-2-go,项目名称:logyard,代码行数:7,代码来源:add.go

示例5: addTestFlags

func addTestFlags(fs *flag.FlagSet) {
	addBuildFlags(fs)
	fs.BoolVar(&testCover, "cover", false, "enable coverage analysis")
	fs.StringVar(&testCoverMode, "covermode", "set", "Set covermode: set (default), count, atomic")
	fs.StringVar(&testCoverPkg, "coverpkg", "", "enable coverage analysis")
	fs.BoolVar(&testVerbose, "v", false, "enable verbose output of subcommands")
}
开发者ID:torfuzx,项目名称:gb,代码行数:7,代码来源:test.go

示例6: Register

func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
	cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
	cmd.DatastoreFlag.Register(ctx, f)

	f.BoolVar(&cmd.force, "f", false, "Force; ignore nonexistent files and arguments")
	f.BoolVar(&cmd.isNamespace, "namespace", false, "Path is uuid of namespace on vsan datastore")
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:7,代码来源:rm.go

示例7: Register

func (cmd *add) Register(f *flag.FlagSet) {
	f.StringVar(&cmd.cluster, "cluster", "*", "Path to cluster")

	f.StringVar(&cmd.license, "license", "", "Assign license key")

	f.BoolVar(&cmd.connect, "connect", true, "Immediately connect to host")
}
开发者ID:kristinn,项目名称:govmomi,代码行数:7,代码来源:add.go

示例8: Register

func (cmd *mkdir) Register(ctx context.Context, f *flag.FlagSet) {
	cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
	cmd.DatastoreFlag.Register(ctx, f)

	f.BoolVar(&cmd.createParents, "p", false, "Create intermediate directories as needed")
	f.BoolVar(&cmd.isNamespace, "namespace", false, "Return uuid of namespace created on vsan datastore")
}
开发者ID:vmware,项目名称:vic,代码行数:7,代码来源:mkdir.go

示例9: 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())
	}
}
开发者ID:jad-b,项目名称:flagit,代码行数:32,代码来源:flagit.go

示例10: Register

func (s *ResourceConfigSpecFlag) Register(f *flag.FlagSet) {
	opts := []struct {
		name  string
		units string
		*types.ResourceAllocationInfo
	}{
		{"CPU", "MHz", &s.CpuAllocation},
		{"Memory", "MB", &s.MemoryAllocation},
	}

	for _, opt := range opts {
		prefix := strings.ToLower(opt.name)[:3]
		shares := (*sharesInfo)(opt.Shares)

		expandableReservation := false
		if v := opt.ExpandableReservation; v != nil {
			expandableReservation = *v
		}

		// Initialize bool pointer
		opt.ExpandableReservation = types.NewBool(false)

		f.Int64Var(&opt.Limit, prefix+".limit", 0, opt.name+" limit in "+opt.units)
		f.Int64Var(&opt.Reservation, prefix+".reservation", 0, opt.name+" reservation in "+opt.units)
		f.BoolVar(opt.ExpandableReservation, prefix+".expandable", expandableReservation, opt.name+" expandable reservation")
		f.Var(shares, prefix+".shares", opt.name+" shares level or number")
	}
}
开发者ID:EricYT,项目名称:govmomi,代码行数:28,代码来源:resource_config_spec.go

示例11: ParamsParser

// ParamsParser implements a command line parameters parser that takes a string
// and returns a Parameters structure in an interface. It will display the module
// help if the arguments string spell the work 'help'
func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err                    error
		lm, nm, li, ni, ci, lp flagParam
		fs                     flag.FlagSet
		namespaces             bool
	)
	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		fmt.Println(cmd_help)
		return nil, fmt.Errorf("help printed")
	}
	fs.Init("file", flag.ContinueOnError)
	fs.Var(&lm, "lm", "see help")
	fs.Var(&nm, "nm", "see help")
	fs.Var(&li, "li", "see help")
	fs.Var(&ni, "ni", "see help")
	fs.Var(&ci, "ci", "see help")
	fs.Var(&lp, "lp", "see help")
	fs.BoolVar(&namespaces, "namespaces", false, "see help")
	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	var p params
	p.LocalMAC = lm
	p.NeighborMAC = nm
	p.LocalIP = li
	p.NeighborIP = ni
	p.ConnectedIP = ci
	p.ListeningPort = lp
	p.SearchNamespaces = namespaces

	r.Parameters = p
	return p, r.ValidateParameters()
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:38,代码来源:paramscreator.go

示例12: flRun

func flRun(fl *flag.FlagSet) {
	flPodManifest(fl)
	SaveIDFlag(fl)
	fl.Var(&flAppName, "app", "Specify app to run for a multi-app pod")
	fl.BoolVar(&flDestroy, "destroy", false, "Destroy pod when done")
	fl.BoolVar(&flTerminal, "t", false, "Attach app to the terminal (single-app containers only)")
}
开发者ID:saper,项目名称:jetpack,代码行数:7,代码来源:pod.go

示例13: Register

func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
	cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
	cmd.VirtualMachineFlag.Register(ctx, f)

	f.BoolVar(&cmd.recursive, "r", false, "Remove snapshot children")
	f.BoolVar(&cmd.consolidate, "c", true, "Consolidate disks")
}
开发者ID:frapposelli,项目名称:govmomi,代码行数:7,代码来源:remove.go

示例14: RegisterFlags

func (cmd *GroupList) RegisterFlags(f *flag.FlagSet) {
	f.StringVar(&cmd.group, "group", "koding", "Name of the instance group to list.")
	f.StringVar(&cmd.env, "env", "dev", "Kloud environment.")
	f.StringVar(&cmd.tags, "tags", "", "Tags to filter instances.")
	f.StringVar(&cmd.hostname, "hostname", "", "Hostname to filter instances.")
	f.BoolVar(&cmd.entries, "entries", false, "Whether the lookup only entries as oppose to full details.")
}
开发者ID:koding,项目名称:koding,代码行数:7,代码来源:group.go

示例15: do

// do is the workhorse, broken out of main to make testing easier.
func do(writer io.Writer, flagSet *flag.FlagSet, args []string) (err error) {
	flagSet.Usage = usage
	unexported = false
	matchCase = false
	flagSet.BoolVar(&unexported, "u", false, "show unexported symbols as well as exported")
	flagSet.BoolVar(&matchCase, "c", false, "symbol matching honors case (paths not affected)")
	flagSet.Parse(args)
	buildPackage, userPath, symbol := parseArgs(flagSet.Args())
	symbol, method := parseSymbol(symbol)
	pkg := parsePackage(writer, buildPackage, userPath)
	defer func() {
		pkg.flush()
		e := recover()
		if e == nil {
			return
		}
		pkgError, ok := e.(PackageError)
		if ok {
			err = pkgError
			return
		}
		panic(e)
	}()
	switch {
	case symbol == "":
		pkg.packageDoc()
		return
	case method == "":
		pkg.symbolDoc(symbol)
	default:
		pkg.methodDoc(symbol, method)
	}
	return nil
}
开发者ID:Ericean,项目名称:go,代码行数:35,代码来源:main.go


注:本文中的flag.FlagSet.BoolVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。