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


Golang FlagSet.Int方法代码示例

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


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

示例1: ApplyWithError

// ApplyWithError populates the flag given the flag set and environment
func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				envValInt, err := strconv.ParseInt(envVal, 0, 64)
				if err != nil {
					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
				}
				f.Value = int(envValInt)
				break
			}
		}
	}

	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.IntVar(f.Destination, name, f.Value, f.Usage)
			return
		}
		set.Int(name, f.Value, f.Usage)
	})

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

示例2: Flags

func (cmd *pullCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
	cmd.noClobber = fs.Bool(drive.CLIOptionNoClobber, false, "prevents overwriting of old content")
	cmd.export = fs.String(
		"export", "", "comma separated list of formats to export your docs + sheets files")
	cmd.recursive = fs.Bool("r", true, "performs the pull action recursively")
	cmd.noPrompt = fs.Bool(drive.NoPromptKey, false, "shows no prompt before applying the pull action")
	cmd.hidden = fs.Bool(drive.HiddenKey, false, "allows pulling of hidden paths")
	cmd.force = fs.Bool(drive.ForceKey, false, "forces a pull even if no changes present")
	cmd.ignoreChecksum = fs.Bool(drive.CLIOptionIgnoreChecksum, true, drive.DescIgnoreChecksum)
	cmd.ignoreConflict = fs.Bool(drive.CLIOptionIgnoreConflict, false, drive.DescIgnoreConflict)
	cmd.ignoreNameClashes = fs.Bool(drive.CLIOptionIgnoreNameClashes, false, drive.DescIgnoreNameClashes)
	cmd.exportsDir = fs.String("export-dir", "", "directory to place exports")
	cmd.matches = fs.Bool(drive.MatchesKey, false, "search by prefix")
	cmd.piped = fs.Bool("piped", false, "if true, read content from stdin")
	cmd.quiet = fs.Bool(drive.QuietKey, false, "if set, do not log anything but errors")
	cmd.excludeOps = fs.String(drive.CLIOptionExcludeOperations, "", drive.DescExcludeOps)
	cmd.byId = fs.Bool(drive.CLIOptionId, false, "pull by id instead of path")
	cmd.skipMimeKey = fs.String(drive.CLIOptionSkipMime, "", drive.DescSkipMime)
	cmd.explicitlyExport = fs.Bool(drive.CLIOptionExplicitlyExport, false, drive.DescExplicitylPullExports)
	cmd.verbose = fs.Bool(drive.CLIOptionVerboseKey, false, drive.DescVerbose)
	cmd.depth = fs.Int(drive.DepthKey, drive.DefaultMaxTraversalDepth, "max traversal depth")
	cmd.fixClashes = fs.Bool(drive.CLIOptionFixClashesKey, false, drive.DescFixClashes)

	return fs
}
开发者ID:WangKaimin,项目名称:drive,代码行数:25,代码来源:main.go

示例3: TestLoadConfig

func TestLoadConfig(t *testing.T) {
	var flagSet flag.FlagSet
	a := flagSet.Int("a", -1, "for test")
	b := flagSet.Bool("b", true, "for test")
	c := flagSet.String("c", "-1", "for test")
	da := flagSet.Int("d.a", -1, "for test")
	dd := flagSet.Bool("d.d", false, "for test")
	dc := flagSet.String("d.c", "-1", "for test")
	e := loadConfig("config_test.txt", &flagSet, false)
	if nil != e {
		t.Error(e)
		return
	}

	if *a != 1 {
		t.Error("a != 1")
	}
	if !*b {
		t.Error("b != true")
	}
	if "abc" != *c {
		t.Error("c != \"abc\"")
	}
	if *da != 1323 {
		t.Error("d.a != 1323")
	}
	if !*dd {
		t.Error("db != true")
	}
	if "67" != *dc {
		t.Errorf("dc != \"67\", actual is %s", *dc)
	}
}
开发者ID:runner-mei,项目名称:delayed_job,代码行数:33,代码来源:config_test.go

示例4: multisnapshotCmd

func multisnapshotCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) {
	concurrency := subFlags.Int("concurrency", 8, "how many compression jobs to run simultaneously")
	spec := subFlags.String("spec", "-", "shard specification")
	tablesString := subFlags.String("tables", "", "dump only this comma separated list of tables")
	skipSlaveRestart := subFlags.Bool("skip-slave-restart", false, "after the snapshot is done, do not restart slave replication")
	maximumFilesize := subFlags.Uint64("maximum-file-size", 128*1024*1024, "the maximum size for an uncompressed data file")
	subFlags.Parse(args)
	if subFlags.NArg() != 2 {
		relog.Fatal("action multisnapshot requires <db name> <key name>")
	}

	shards, err := key.ParseShardingSpec(*spec)
	if err != nil {
		relog.Fatal("multisnapshot failed: %v", err)
	}
	var tables []string
	if *tablesString != "" {
		tables = strings.Split(*tablesString, ",")
	}
	filenames, err := mysqld.CreateMultiSnapshot(shards, subFlags.Arg(0), subFlags.Arg(1), tabletAddr, false, *concurrency, tables, *skipSlaveRestart, *maximumFilesize, nil)
	if err != nil {
		relog.Fatal("multisnapshot failed: %v", err)
	} else {
		relog.Info("manifest locations: %v", filenames)
	}
}
开发者ID:Eric-Chen,项目名称:vitess,代码行数:26,代码来源:mysqlctl.go

示例5: commandVtGateSplitQuery

func commandVtGateSplitQuery(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
	server := subFlags.String("server", "", "VtGate server to connect to")
	bindVariables := newBindvars(subFlags)
	connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client")
	splitColumn := subFlags.String("split_column", "", "force the use of this column to split the query")
	splitCount := subFlags.Int("split_count", 16, "number of splits to generate")
	keyspace := subFlags.String("keyspace", "", "keyspace to send query to")
	if err := subFlags.Parse(args); err != nil {
		return err
	}
	if subFlags.NArg() != 1 {
		return fmt.Errorf("the <sql> argument is required for the VtGateSplitQuery command")
	}

	vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout, "")
	if err != nil {
		return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err)
	}
	defer vtgateConn.Close()
	r, err := vtgateConn.SplitQuery(ctx, *keyspace, subFlags.Arg(0), *bindVariables, *splitColumn, int64(*splitCount))
	if err != nil {
		return fmt.Errorf("SplitQuery failed: %v", err)
	}
	return printJSON(wr.Logger(), r)
}
开发者ID:dumbunny,项目名称:vitess,代码行数:25,代码来源:query.go

示例6: commandVtGateSplitQuery

func commandVtGateSplitQuery(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
	server := subFlags.String("server", "", "VtGate server to connect to")
	bindVariables := newBindvars(subFlags)
	connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client")
	splitCount := subFlags.Int("split_count", 16, "number of splits to generate")
	keyspace := subFlags.String("keyspace", "", "keyspace to send query to")
	if err := subFlags.Parse(args); err != nil {
		return err
	}
	if subFlags.NArg() != 1 {
		return fmt.Errorf("the <sql> argument is required for the VtGateSplitQuery command")
	}

	vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout)
	if err != nil {
		return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err)
	}
	defer vtgateConn.Close()
	r, err := vtgateConn.SplitQuery(ctx, *keyspace, tproto.BoundQuery{
		Sql:           subFlags.Arg(0),
		BindVariables: *bindVariables,
	}, *splitCount)
	if err != nil {
		return fmt.Errorf("SplitQuery failed: %v", err)
	}
	wr.Logger().Printf("%v\n", jscfg.ToJSON(r))
	return nil
}
开发者ID:zhzhy917,项目名称:vitess,代码行数:28,代码来源:query.go

示例7: Flags

func (cmd *listCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
	cmd.depth = fs.Int(drive.DepthKey, 1, "maximum recursion depth")
	cmd.hidden = fs.Bool(drive.HiddenKey, false, "list all paths even hidden ones")
	cmd.files = fs.Bool("f", false, "list only files")
	cmd.directories = fs.Bool("d", false, "list all directories")
	cmd.longFmt = fs.Bool("l", false, "long listing of contents")
	cmd.pageSize = fs.Int64("p", 100, "number of results per pagination")
	cmd.shared = fs.Bool("shared", false, "show files that are shared with me")
	cmd.inTrash = fs.Bool(drive.TrashedKey, false, "list content in the trash")
	cmd.version = fs.Bool("version", false, "show the number of times that the file has been modified on \n\t\tthe server even with changes not visible to the user")
	cmd.noPrompt = fs.Bool(drive.NoPromptKey, false, "shows no prompt before pagination")
	cmd.owners = fs.Bool("owners", false, "shows the owner names per file")
	cmd.recursive = fs.Bool("r", false, "recursively list subdirectories")
	cmd.sort = fs.String(drive.SortKey, "", drive.DescSort)
	cmd.matches = fs.Bool(drive.MatchesKey, false, "list by prefix")
	cmd.quiet = fs.Bool(drive.QuietKey, false, "if set, do not log anything but errors")
	cmd.skipMimeKey = fs.String(drive.CLIOptionSkipMime, "", drive.DescSkipMime)
	cmd.matchMimeKey = fs.String(drive.CLIOptionMatchMime, "", drive.DescMatchMime)
	cmd.exactTitle = fs.String(drive.CLIOptionExactTitle, "", drive.DescExactTitle)
	cmd.matchOwner = fs.String(drive.CLIOptionMatchOwner, "", drive.DescMatchOwner)
	cmd.exactOwner = fs.String(drive.CLIOptionExactOwner, "", drive.DescExactOwner)
	cmd.notOwner = fs.String(drive.CLIOptionNotOwner, "", drive.DescNotOwner)
	cmd.byId = fs.Bool(drive.CLIOptionId, false, "list by id instead of path")

	return fs
}
开发者ID:jsmorph,项目名称:drive,代码行数:26,代码来源:main.go

示例8: Flags

func (c *DaemonCmd) Flags(fs *flag.FlagSet) {
	c.dbfile = fs.String("o", "ci.db", "override the default local file name")
	c.port = fs.Int("p", 2020, "override the default local port")
	c.hookport = fs.Int("hp", 2121, "override the default hook port ")
	c.hook = fs.Bool("hook", false, "also start an http Hook server (Get returns a status, Post fire a build)")

}
开发者ID:ericaro,项目名称:sbr,代码行数:7,代码来源:daemonCmd.go

示例9: NewGoCmdWithFlags

// NewGoCmdWithFlags like NewGoCmd, but wl also parse flags configured i flagset
func NewGoCmdWithFlags(flagset *flag.FlagSet, workdir string, args ...string) (*GoCmd, error) {
	if len(args) < 2 {
		return nil, errors.New("GoCmd must have at least two arguments (e.g. go build)")
	}
	if sort.SearchStrings([]string{"build", "run", "test"}, args[1]) > -1 {
		flagset.Int("p", runtime.NumCPU(), "number or parallel builds")
		for _, f := range []string{"x", "v", "n", "a", "work"} {
			flagset.Bool(f, false, "")
		}
		for _, f := range []string{"compiler", "gccgoflags", "gcflags", "ldflags", "tags"} {
			flagset.String(f, "", "")
		}
	}
	switch args[1] {
	case "run":
	case "build":
		flagset.String("o", "", "output: output file")
	case "test":
		for _, f := range []string{"i", "c"} {
			flagset.Bool(f, false, "")
		}
		for _, testflag := range TestFlags {
			flagset.String(testflag, "", "")
			flagset.String("test."+testflag, "", "")
		}
		flagset.Bool("short", false, "")
		flagset.Bool("test.short", false, "")
		flagset.Bool("test.v", false, "")
	default:
		return nil, errors.New("Currently only build run and test commands supported. Sorry.")
	}
	if err := flagset.Parse(args[2:]); err != nil {
		return nil, err
	}
	var params, extra []string
	switch args[1] {
	case "build":
		params = flagset.Args()
	case "run":
		for i, param := range flagset.Args() {
			if !strings.HasSuffix(param, ".go") {
				extra = flagset.Args()[i:]
				break
			}
			params = append(params, param)
		}
	case "test":
		for i, param := range flagset.Args() {
			if strings.HasPrefix(param, "-") {
				extra = flagset.Args()[i:]
				break
			}
			params = append(params, param)
		}
	default:
		return nil, errors.New("Currently only build run and test commands supported")
	}
	return &GoCmd{make(map[string]string), workdir, args[0], args[1], FromFlagSet(flagset), params, extra}, nil
}
开发者ID:elazarl,项目名称:gosloppy,代码行数:60,代码来源:buildcmd.go

示例10: addSet

func (c *flags) addSet(s *flag.FlagSet) {
	cassandraAddr := s.String("cassandra-addr", "", "Address to a single Cassandra node")
	c.cassandraAddr = cassandraAddr

	cassandraRepl := s.Int("cassandra-repl", 1, "Replication factor to use for the oinker keyspace in Cassandra")
	c.cassandraRepl = cassandraRepl

	address := s.String("address", "0.0.0.0:8080", "host:port on which to listen")
	c.address = address
}
开发者ID:mesosphere,项目名称:oinker-go,代码行数:10,代码来源:flags.go

示例11: Flags

// Startup flags
func (sc *CompareCommand) Flags(fs *flag.FlagSet) *flag.FlagSet {
	sc.setName = fs.String("s", "", "Select records from this set")
	sc.beforeDate = fs.String("B", "", "Select records that were updated before date (YYYY-MM-DD)")
	sc.afterDate = fs.String("A", "", "Select records that were updated after date (YYYY-MM-DD)")
	sc.firstResult = fs.Int("f", 0, "Index of first record to retrieve")
	sc.fromFile = fs.String("F", "", "Read identifiers from a file")
	sc.maxResults = fs.Int("c", 100000, "Maximum number of records to retrieve")
	sc.compareContent = fs.Bool("C", false, "Compares the metadata content of common metadata records")

	return fs
}
开发者ID:njt99,项目名称:oaipmh,代码行数:12,代码来源:cmdcompare.go

示例12: DefineFlags

func (a *run_tagger_action) DefineFlags(fs *flag.FlagSet) {
	a.AddDefaultArgs(fs)

	a.lexiconPath = fs.String("lexicon_path", "/tmp/tokens",
		"Path and filename to the lexicon file.  One word per line.")

	a.dbUser = fs.String("db.user", "", "")
	a.dbPass = fs.String("db.pass", "", "")
	a.dbName = fs.String("db.name", "", "")
	a.workers = fs.Int("workers", 10, "Number of workers and db connections to make")
}
开发者ID:Georgetown-IR-Lab,项目名称:ocr-correction,代码行数:11,代码来源:tagger.go

示例13: Flags

func (lc *ListCommand) Flags(fs *flag.FlagSet) *flag.FlagSet {
	lc.setName = fs.String("s", "", "Select records from this set")
	lc.beforeDate = fs.String("B", "", "Select records that were updated before date (YYYY-MM-DD)")
	lc.afterDate = fs.String("A", "", "Select records that were updated after date (YYYY-MM-DD)")
	lc.flagDetailed = fs.Bool("l", false, "Use detailed listing format")
	lc.showDeleted = fs.Bool("d", false, "Show deleted records, along with active ones")
	lc.onlyShowDeleted = fs.Bool("D", false, "Only show deleted records")
	lc.firstResult = fs.Int("f", 0, "Index of first record to retrieve")
	lc.maxResults = fs.Int("c", 100000, "Maximum number of records to retrieve")
	lc.listRecords = fs.Bool("R", false, "Use ListRecord instead of ListIdentifier")

	return fs
}
开发者ID:njt99,项目名称:oaipmh,代码行数:13,代码来源:cmdlist.go

示例14: Apply

func (f IntFlag) Apply(set *flag.FlagSet) {
	if f.EnvVar != "" {
		if envVal := os.Getenv(f.EnvVar); envVal != "" {
			envValInt, err := strconv.ParseUint(envVal, 10, 64)
			if err == nil {
				f.Value = int(envValInt)
			}
		}
	}

	eachName(f.Name, func(name string) {
		set.Int(name, f.Value, f.Usage)
	})
}
开发者ID:CowLeo,项目名称:gopm,代码行数:14,代码来源:flag.go

示例15: commandLegacySplitClone

func commandLegacySplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
	excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude")
	strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker LegacySplitClone --strategy=-help k/s' for more info")
	sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
	destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert")
	destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
	minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets before taking out one")
	maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)")
	if err := subFlags.Parse(args); err != nil {
		return nil, err
	}
	if subFlags.NArg() != 1 {
		subFlags.Usage()
		return nil, fmt.Errorf("command LegacySplitClone requires <keyspace/shard>")
	}

	keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
	if err != nil {
		return nil, err
	}
	var excludeTableArray []string
	if *excludeTables != "" {
		excludeTableArray = strings.Split(*excludeTables, ",")
	}
	worker, err := NewLegacySplitCloneWorker(wr, wi.cell, keyspace, shard, excludeTableArray, *strategy, *sourceReaderCount, *destinationPackCount, *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS)
	if err != nil {
		return nil, fmt.Errorf("cannot create split clone worker: %v", err)
	}
	return worker, nil
}
开发者ID:erzel,项目名称:vitess,代码行数:30,代码来源:legacy_split_clone_cmd.go


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