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") }
// 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.") }
// 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 }
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}}'") }
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") }
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") }
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") }
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") }
// 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()) } }
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") } }
// 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() }
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)") }
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") }
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.") }
// 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 }
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) { cmd.PermissionFlag, ctx = NewPermissionFlag(ctx) cmd.PermissionFlag.Register(ctx, f) f.StringVar(&cmd.Principal, "principal", "", "User or group for which the permission is defined") f.BoolVar(&cmd.Group, "group", false, "True, if principal refers to a group name; false, for a user name") }
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 }
func addFetchFlags(fs *flag.FlagSet) { fs.StringVar(&branch, "branch", "", "branch of the package") fs.StringVar(&revision, "revision", "", "revision of the package") fs.StringVar(&tag, "tag", "", "tag of the package") fs.BoolVar(&noRecurse, "no-recurse", false, "do not fetch recursively") fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols") }
// RegisterFlags sets the flags for the command - "team apply <flags>". func (cmd *TeamApply) RegisterFlags(f *flag.FlagSet) { f.StringVar(&cmd.Provider, "p", "aws", "Team provider name.") f.StringVar(&cmd.Team, "team", "koding", "Team name.") f.StringVar(&cmd.StackID, "sid", "", "Compute stack ID.") f.BoolVar(&cmd.Destroy, "del", false, "Destroy resources.") f.StringVar(&cmd.Username, "u", defaultUsername, "Username for the kloud request.") }
func (cmd *connect) Register(ctx context.Context, f *flag.FlagSet) { cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) cmd.VirtualMachineFlag.Register(ctx, f) f.StringVar(&cmd.device, "device", "", "serial port device name") f.BoolVar(&cmd.client, "client", false, "Use client direction") }
func (cmd *service) Register(ctx context.Context, f *flag.FlagSet) { cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) cmd.HostSystemFlag.Register(ctx, f) f.BoolVar(&cmd.Enable, "enable", false, "Enable service") f.BoolVar(&cmd.Disable, "disable", false, "Disable service") }
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) { cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) cmd.HostSystemFlag.Register(ctx, f) modes := []string{ string(types.HostMountModeReadOnly), string(types.HostMountModeReadWrite), } f.StringVar(&cmd.Name, "name", "", "Datastore name") f.Var(&cmd.Type, "type", fmt.Sprintf("Datastore type (%s)", strings.Join(allTypes, "|"))) f.BoolVar(&cmd.Force, "force", false, "Ignore DuplicateName error if datastore is already mounted on a host") // Options for NAS f.StringVar(&cmd.RemoteHost, "remote-host", "", "Remote hostname of the NAS datastore") f.StringVar(&cmd.RemotePath, "remote-path", "", "Remote path of the NFS mount point") f.StringVar(&cmd.AccessMode, "mode", modes[0], fmt.Sprintf("Access mode for the mount point (%s)", strings.Join(modes, "|"))) f.StringVar(&cmd.UserName, "username", "", "Username to use when connecting (CIFS only)") f.StringVar(&cmd.Password, "password", "", "Password to use when connecting (CIFS only)") // Options for VMFS f.StringVar(&cmd.DiskCanonicalName, "disk", "", "Canonical name of disk (VMFS only)") // Options for Local f.StringVar(&cmd.Path, "path", "", "Local directory path for the datastore (local only)") }
func (cmd *enter) Register(ctx context.Context, f *flag.FlagSet) { cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) cmd.HostSystemFlag.Register(ctx, f) f.Var(flags.NewInt32(&cmd.timeout), "timeout", "Timeout") f.BoolVar(&cmd.evacuate, "evacuate", false, "Evacuate powered off VMs") }
func policyRuleAddUpdateInitOptions(flagSet *flag.FlagSet) { flagSet.StringVar(&policyRuleOpts.policy, "policy", "", "Policy name or uuid") flagSet.StringVar(&policyRuleOpts.srcIpAddress, "source-address", "", "Source IP address prefix") flagSet.StringVar(&policyRuleOpts.dstIpAddress, "destination-address", "", "Destination IP address prefix") flagSet.StringVar(&policyRuleOpts.srcNetwork, "source-network", "", "Virtual-network name for source IP address") flagSet.StringVar(&policyRuleOpts.dstNetwork, "destination-network", "", "Virtual-network name for destination IP address") var allowedProtocolValues []string for key, _ := range protocolValues { allowedProtocolValues = append(allowedProtocolValues, key) } flagSet.Var(&policyRuleOpts.protocol, "protocol", fmt.Sprintf("IP protocol (one of [%s])", strings.Join(allowedProtocolValues, ","))) flagSet.Var(&policyRuleOpts.srcPort, "source-port", "Transport protocol (e.g. tcp, udp) source port") flagSet.Var(&policyRuleOpts.dstPort, "destination-port", "Transport protocol (e.g. tcp, udp) destination port") flagSet.BoolVar(&policyRuleOpts.actionDrop, "drop", false, "Discard packets") flagSet.BoolVar(&policyRuleOpts.actionDrop, "pass", false, "Accept packets (default)") }
func (flag *ClientFlag) Register(ctx context.Context, f *flag.FlagSet) { flag.RegisterOnce(func() { flag.DebugFlag.Register(ctx, f) { flag.Set(os.Getenv(envURL)) usage := fmt.Sprintf("%s [%s]", cDescr, envURL) f.Var(flag, "u", usage) } { flag.username = os.Getenv(envUsername) flag.password = os.Getenv(envPassword) } { value := os.Getenv(envCertificate) usage := fmt.Sprintf("Certificate [%s]", envCertificate) f.StringVar(&flag.cert, "cert", value, usage) } { value := os.Getenv(envPrivateKey) usage := fmt.Sprintf("Private key [%s]", envPrivateKey) f.StringVar(&flag.key, "key", value, usage) } { insecure := false switch env := strings.ToLower(os.Getenv(envInsecure)); env { case "1", "true": insecure = true } usage := fmt.Sprintf("Skip verification of server certificate [%s]", envInsecure) f.BoolVar(&flag.insecure, "k", insecure, usage) } { persist := true switch env := strings.ToLower(os.Getenv(envPersist)); env { case "0", "false": persist = false } usage := fmt.Sprintf("Persist session to disk [%s]", envPersist) f.BoolVar(&flag.persist, "persist-session", persist, usage) } { env := os.Getenv(envMinAPIVersion) if env == "" { env = "5.5" } flag.minAPIVersion = env } }) }
func initInstallCommand(flags *flag.FlagSet, installer, defaultDBPath, defaultProfilesPath string) { initCommon(flags, &installFlags.commonFlagValues, installer, defaultDBPath, defaultProfilesPath) profiles.RegisterTargetAndEnvFlags(flags, &installFlags.target) flags.BoolVar(&installFlags.force, "force", false, "force install the profile even if it is already installed") for _, name := range profilesmanager.Managers() { profilesmanager.LookupManager(name).AddFlags(flags, profiles.Install) } }
func (cmd *find) Register(f *flag.FlagSet) { f.BoolVar(&cmd.check, "c", true, "Check if esx firewall is enabled") f.BoolVar(&cmd.enabled, "enabled", true, "Find enabled rule sets if true, disabled if false") f.StringVar((*string)(&cmd.Direction), "direction", string(types.HostFirewallRuleDirectionOutbound), "Direction") f.StringVar((*string)(&cmd.PortType), "type", string(types.HostFirewallRulePortTypeDst), "Port type") f.StringVar((*string)(&cmd.Protocol), "proto", string(types.HostFirewallRuleProtocolTcp), "Protocol") f.IntVar(&cmd.Port, "port", 0, "Port") }
func (cmd *mktemp) Register(ctx context.Context, f *flag.FlagSet) { cmd.GuestFlag, ctx = newGuestFlag(ctx) cmd.GuestFlag.Register(ctx, f) f.BoolVar(&cmd.dir, "d", false, "Make a directory instead of a file") f.StringVar(&cmd.prefix, "t", "", "Prefix") f.StringVar(&cmd.suffix, "s", "", "Suffix") }
func get_my_config_bool(c *config.Config, f *flag.FlagSet, val *Config_value_bool) { //overwrite variable if defined in config file if c != nil { getDefinedValueBool(c, val.Section, val.Key, val.Target) } //overwrite variable if defined on command line (default values are overwritten by config file) f.BoolVar(val.Target, val.Key, *val.Target, val.Descr_short) }
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) { cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) cmd.VirtualMachineFlag.Register(ctx, f) f.BoolVar(&cmd.memory, "m", true, "Include memory state") f.BoolVar(&cmd.quiesce, "q", false, "Quiesce guest file system") f.StringVar(&cmd.description, "d", "", "Snapshot description") }