本文整理匯總了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")
}
示例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.")
}
示例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
}
示例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}}'")
}
示例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")
}
示例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")
}
示例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")
}
示例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")
}
示例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())
}
}
示例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")
}
}
示例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()
}
示例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)")
}
示例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")
}
示例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.")
}
示例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
}