本文整理匯總了Golang中flag.FlagSet.StringVar方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagSet.StringVar方法的具體用法?Golang FlagSet.StringVar怎麽用?Golang FlagSet.StringVar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.StringVar方法的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 *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")
}
示例3: AddFlags
// AddFlags adds flags for sous rectify.
func (sr *SousRectify) AddFlags(fs *flag.FlagSet) {
MustAddFlags(fs, &sr.SourceFlags, RectifyFilterFlagsHelp)
fs.StringVar(&sr.flags.dryrun, "dry-run", "none",
"prevent rectify from actually changing things - "+
"values are none,scheduler,registry,both")
}
示例4: 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.path, "dvs", "", "DVS path")
f.StringVar(&cmd.pnic, "pnic", "vmnic0", "Name of the host physical NIC")
}
示例5: Register
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
cmd.DrsConfig = new(types.ClusterDrsConfigInfo)
cmd.DasConfig = new(types.ClusterDasConfigInfo)
cmd.VsanConfig = new(types.VsanClusterConfigInfo)
cmd.VsanConfig.DefaultConfig = new(types.VsanClusterConfigInfoHostDefaultInfo)
// DRS
f.Var(flags.NewOptionalBool(&cmd.DrsConfig.Enabled), "drs-enabled", "Enable DRS")
drsModes := []string{
string(types.DrsBehaviorManual),
string(types.DrsBehaviorPartiallyAutomated),
string(types.DrsBehaviorFullyAutomated),
}
f.StringVar((*string)(&cmd.DrsConfig.DefaultVmBehavior), "drs-mode", "",
"DRS behavior for virtual machines: "+strings.Join(drsModes, ", "))
// HA
f.Var(flags.NewOptionalBool(&cmd.DasConfig.Enabled), "ha-enabled", "Enable HA")
// vSAN
f.Var(flags.NewOptionalBool(&cmd.VsanConfig.Enabled), "vsan-enabled", "Enable vSAN")
f.Var(flags.NewOptionalBool(&cmd.VsanConfig.DefaultConfig.AutoClaimStorage), "vsan-autoclaim", "")
}
示例6: policyRuleAddUpdateInitOptions
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)")
}
示例7: Register
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")
}
示例8: 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}}'")
}
示例9: influxdbCommandLine
func influxdbCommandLine(cli *flag.FlagSet) CommandLineHandler {
ix := &influx{
logger: NewLogger("[ostent sendto-influxdb] "),
RefreshFlag: flags.Period{Duration: 10 * time.Second}, // 10s default
// ServerAddr: flags.NewBind(8086),
}
cli.Var(&ix.RefreshFlag, "influxdb-refresh", "InfluxDB refresh interval")
cli.StringVar(&ix.ServerAddr, "sendto-influxdb", "", "InfluxDB server address")
cli.StringVar(&ix.Database, "influxdb-database", "ostent", "InfluxDB database")
cli.StringVar(&ix.Username, "influxdb-username", "", "InfluxDB username")
cli.StringVar(&ix.Password, "influxdb-password", "", "InfluxDB password")
return func() (AtexitHandler, bool, error) {
if ix.ServerAddr == "" {
return nil, false, nil
}
ostent.AddBackground(func(defaultPeriod flags.Period) {
/* if ix.RefreshFlag.Duration == 0 { // if .RefreshFlag had no default
ix.RefreshFlag = defaultPeriod
} */
go influxdb.Influxdb(ostent.Reg1s.Registry, ix.RefreshFlag.Duration, &influxdb.Config{
Host: ix.ServerAddr, //.String(),
Database: ix.Database,
Username: ix.Username,
Password: ix.Password,
})
})
return nil, false, nil
}
}
示例10: 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
}
示例11: getCmd
func getCmd(flagset *flag.FlagSet) {
flagset.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s get [args...] key\n", os.Args[0])
flagset.PrintDefaults()
}
flagset.StringVar(&secretKeyring, "secret-keyring", DefaultConfig.SecretKeyring, "path to armored secret keyring")
flagset.Parse(os.Args[2:])
key := flagset.Arg(0)
if key == "" {
flagset.Usage()
os.Exit(1)
}
backendStore, err := getBackendStore(backendName, endpoint)
if err != nil {
log.Fatal(err)
}
log.Printf("Looking at consul node %q\n", nodeKey(key))
if plaintext {
value, err := getPlain(nodeKey(key), backendStore)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", value)
return
}
value, err := getEncrypted(nodeKey(key), secretKeyring, backendStore)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", value)
}
示例12: Register
func (cmd *create) Register(f *flag.FlagSet) {
cmd.configSpec = new(types.VMwareDVSConfigSpec)
cmd.DVSCreateSpec.ConfigSpec = cmd.configSpec
f.StringVar(&cmd.parent, "parent", "", "Path to parent folder for the new dvs")
}
示例13: listCmd
func listCmd(flagset *flag.FlagSet) {
flagset.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s list [args...] key\n", os.Args[0])
flagset.PrintDefaults()
}
flagset.StringVar(&secretKeyring, "secret-keyring", ".secring.gpg", "path to armored secret keyring")
flagset.Parse(os.Args[2:])
key := flagset.Arg(0)
if key == "" {
flagset.Usage()
os.Exit(1)
}
backendStore, err := getBackendStore(backendName, endpoint)
if err != nil {
log.Fatal(err)
}
if plaintext {
list, err := listPlain(key, backendStore)
if err != nil {
log.Fatal(err)
}
for _, kv := range list {
fmt.Printf("%s: %s", kv.Key, kv.Value)
}
return
}
list, err := listEncrypted(key, secretKeyring, backendStore)
if err != nil {
log.Fatal(err)
}
for _, kv := range list {
fmt.Printf("%s: %s", kv.Key, kv.Value)
}
}
示例14: 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")
}
示例15: RegisterFlags
func (cmd *TeamInit) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cmd.Provider, "p", "vagrant", "Team provider name.")
f.StringVar(&cmd.KlientID, "klient", "", "ID of the klient kite.")
f.StringVar(&cmd.Team, "team", "koding", "Team name. If empty will get autogenerated.")
f.StringVar(&cmd.StackTemplate, "stack", "-", "Stack template content.")
f.StringVar(&cmd.Username, "u", defaultUsername, "Username for the kloud request.")
}