當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FlagSet.StringVar方法代碼示例

本文整理匯總了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")
}
開發者ID:robvanmieghem,項目名稱:machine,代碼行數:7,代碼來源:add.go

示例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")
}
開發者ID:robvanmieghem,項目名稱:machine,代碼行數:7,代碼來源:command.go

示例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")
}
開發者ID:opentable,項目名稱:sous,代碼行數:8,代碼來源:sous_rectify.go

示例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")
}
開發者ID:frapposelli,項目名稱:govmomi,代碼行數:7,代碼來源:add.go

示例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", "")
}
開發者ID:jak-atx,項目名稱:vic,代碼行數:27,代碼來源:change.go

示例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)")
}
開發者ID:netturpin,項目名稱:contrail-go-api,代碼行數:27,代碼來源:policy.go

示例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")
}
開發者ID:tjyang,項目名稱:govmomi,代碼行數:7,代碼來源:remove.go

示例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}}'")
}
開發者ID:way-2-go,項目名稱:logyard,代碼行數:7,代碼來源:add.go

示例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
	}
}
開發者ID:vadv,項目名稱:ostent,代碼行數:29,代碼來源:influxdb.go

示例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
}
開發者ID:paultag,項目名稱:go-config,代碼行數:35,代碼來源:config.go

示例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)
}
開發者ID:jsipprell,項目名稱:crypt,代碼行數:33,代碼來源:cmd.go

示例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")
}
開發者ID:kristinn,項目名稱:govmomi,代碼行數:7,代碼來源:create.go

示例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)
	}
}
開發者ID:CyCoreSystems,項目名稱:coreos-kubernetes,代碼行數:35,代碼來源:cmd.go

示例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")
}
開發者ID:pcdummy,項目名稱:skynet2,代碼行數:7,代碼來源:config.go

示例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.")
}
開發者ID:koding,項目名稱:koding,代碼行數:7,代碼來源:team.go


注:本文中的flag.FlagSet.StringVar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。