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


Golang FlagSet.Usage方法代码示例

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


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

示例1: RunCommand

// RunCommand detects the project root, parses flags and runs the Command.
func RunCommand(fs *flag.FlagSet, cmd *Command, projectroot, goroot string, args []string) error {
	if cmd.AddFlags != nil {
		cmd.AddFlags(fs)
	}
	if err := fs.Parse(args); err != nil {
		fs.Usage()
		os.Exit(1)
	}
	args = fs.Args() // reset to the remaining arguments

	if projectroot == "" {
		return fmt.Errorf("project root is blank")
	}

	root, err := FindProjectroot(projectroot)
	if err != nil {
		return fmt.Errorf("could not locate project root: %v", err)
	}
	project := gb.NewProject(root)

	gb.Debugf("project root %q", project.Projectdir())

	ctx, err := project.NewContext(
		gb.GcToolchain(),
	)
	if err != nil {
		return fmt.Errorf("unable to construct context: %v", err)
	}
	gb.Debugf("args: %v", args)
	return cmd.Run(ctx, args)
}
开发者ID:acasajus,项目名称:gb,代码行数:32,代码来源:cmd.go

示例2: commandVerticalSplitClone

func commandVerticalSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
	tables := subFlags.String("tables", "", "comma separated list of tables to replicate (used for vertical split)")
	strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'mysqlctl multirestore -strategy=-help' 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")
	minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible")
	destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
	if err := subFlags.Parse(args); err != nil {
		return nil, err
	}
	if subFlags.NArg() != 1 {
		subFlags.Usage()
		return nil, fmt.Errorf("command VerticalSplitClone requires <destination keyspace/shard>")
	}

	keyspace, shard, err := topo.ParseKeyspaceShardString(subFlags.Arg(0))
	if err != nil {
		return nil, err
	}
	var tableArray []string
	if *tables != "" {
		tableArray = strings.Split(*tables, ",")
	}
	worker, err := NewVerticalSplitCloneWorker(wr, wi.cell, keyspace, shard, tableArray, *strategy, *sourceReaderCount, *destinationPackCount, uint64(*minTableSizeForSplit), *destinationWriterCount)
	if err != nil {
		return nil, fmt.Errorf("cannot create worker: %v", err)
	}
	return worker, nil
}
开发者ID:haoqoo,项目名称:vitess,代码行数:29,代码来源:vertical_split_clone_cmd.go

示例3: 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

示例4: virtualRouterCreate

func virtualRouterCreate(client *contrail.Client, flagSet *flag.FlagSet) {
	if flagSet.NArg() < 1 {
		flagSet.Usage()
		os.Exit(2)
	}

	if len(virtualRouterCreateOpts.ipAddress) == 0 {
		fmt.Fprintf(os.Stderr,
			"The ip-address option must be specified")
		os.Exit(2)
	}
	matched, err := regexp.MatchString(config.IpAddressPattern,
		virtualRouterCreateOpts.ipAddress)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
	if !matched {
		fmt.Fprintf(os.Stderr, "Invalid IP address specified: %s\n",
			virtualRouterCreateOpts.ipAddress)
		os.Exit(2)
	}

	name := flagSet.Args()[0]
	vrouter := new(types.VirtualRouter)
	vrouter.SetName(name)
	vrouter.SetVirtualRouterIpAddress(virtualRouterCreateOpts.ipAddress)
	client.Create(vrouter)
}
开发者ID:hkumarmk,项目名称:contrail-go-api,代码行数:29,代码来源:virtual_router.go

示例5: verifyFlags

func verifyFlags(opts *Options, fs *flag.FlagSet) {

	if len(fs.Args()) == 0 && opts.showText == "" {
		fs.Usage()
		os.Exit(1)
	}
}
开发者ID:suapapa,项目名称:subtitle-raider,代码行数:7,代码来源:flag.go

示例6: parseArgs

func (a *app) parseArgs(fs *flag.FlagSet, args []string) error {
	fs.SetOutput(a.out)
	fs.Usage = func() {
		fmt.Fprintf(a.out, help, args[0], args[0])
		fs.PrintDefaults()
	}

	fs.Var(&a.typeNames, "type",
		"A generated proto.Message type to generate stubs for (required, repeatable)")
	fs.StringVar(&a.outFile, "out", "proto_gae.gen.go",
		"The name of the output file")
	fs.StringVar(&a.header, "header", copyright, "Header text to put at the top of "+
		"the generated file. Defaults to the Chromium Authors copyright.")

	if err := fs.Parse(args[1:]); err != nil {
		return err
	}
	fail := errors.MultiError(nil)
	if a.typeNames.Data == nil || a.typeNames.Data.Len() == 0 {
		fail = append(fail, errors.New("must specify one or more -type"))
	}
	if !strings.HasSuffix(a.outFile, ".go") {
		fail = append(fail, errors.New("-output must end with '.go'"))
	}
	if len(fail) > 0 {
		for _, e := range fail {
			fmt.Fprintln(a.out, "error:", e)
		}
		fmt.Fprintln(a.out)
		fs.Usage()
		return fail
	}
	return nil
}
开发者ID:tetrafolium,项目名称:gae,代码行数:34,代码来源:proto_gae.go

示例7: 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

示例8: getNumber

func getNumber(fs *flag.FlagSet, args []string) (string, []string) {
	if len(args) < 1 {
		fs.Usage()
		os.Exit(1)
	}
	return args[0], args[1:]
}
开发者ID:seikichi,项目名称:gopl,代码行数:7,代码来源:issues.go

示例9: commandSplitClone

func commandSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
	online := subFlags.Bool("online", defaultOnline, "do online copy (optional approximate copy, source and destination tablets will not be put out of serving, minimizes downtime during offline copy)")
	offline := subFlags.Bool("offline", defaultOffline, "do offline copy (exact copy at a specific GTID, required before shard migration, source and destination tablets will be put out of serving during copy)")
	excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude")
	strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker SplitClone --strategy=-help k/s' for more info")
	sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
	writeQueryMaxRows := subFlags.Int("write_query_max_rows", defaultWriteQueryMaxRows, "maximum number of rows per write query")
	writeQueryMaxSize := subFlags.Int("write_query_max_size", defaultWriteQueryMaxSize, "maximum size (in bytes) per write query")
	writeQueryMaxRowsDelete := subFlags.Int("write_query_max_rows_delete", defaultWriteQueryMaxRows, "maximum number of rows per DELETE FROM write query")
	minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible")
	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 in the source and destination shard at start")
	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 SplitClone 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 := NewSplitCloneWorker(wr, wi.cell, keyspace, shard, *online, *offline, excludeTableArray, *strategy, *sourceReaderCount, *writeQueryMaxRows, *writeQueryMaxSize, *writeQueryMaxRowsDelete, uint64(*minTableSizeForSplit), *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS)
	if err != nil {
		return nil, fmt.Errorf("cannot create split clone worker: %v", err)
	}
	return worker, nil
}
开发者ID:jmptrader,项目名称:vitess,代码行数:35,代码来源:split_clone_cmd.go

示例10: mainReqs

func mainReqs(args []string, flags *flag.FlagSet) {
	flags.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s %s <package-name>\n", os.Args[0], args[0])
		flags.PrintDefaults()
	}
	file := flags.String("graphfile", "", fmt.Sprintf("Path to PyPI dependency graph file.  Defaults to $GOPATH/src/github.com/beyang/cheerio/data/pypi_graph"))
	flags.Parse(args[1:])

	if flags.NArg() < 1 {
		flags.Usage()
		os.Exit(1)
	}

	pkg := cheerio.NormalizedPkgName(flags.Arg(0))

	var pypiG *cheerio.PyPIGraph
	if *file == "" {
		pypiG = cheerio.DefaultPyPIGraph
	} else {
		var err error
		pypiG, err = cheerio.NewPyPIGraph(*file)
		if err != nil {
			fmt.Printf("Error creating PyPI graph: %s\n", err)
			os.Exit(1)
		}
	}

	pkgReq := pypiG.Requires(pkg)
	pkgReqBy := pypiG.RequiredBy(pkg)
	fmt.Printf("pkg %s uses (%d):\n  %s\nand is used by (%d):\n  %s\n", pkg, len(pkgReq), strings.Join(pkgReq, " "), len(pkgReqBy), strings.Join(pkgReqBy, " "))
}
开发者ID:pombredanne,项目名称:cheerio,代码行数:31,代码来源:cheerio.go

示例11: 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

示例12: getOwnerAndRepo

func getOwnerAndRepo(fs *flag.FlagSet, args []string) (string, string, []string) {
	if len(args) < 2 {
		fs.Usage()
		os.Exit(1)
	}
	s := strings.Split(args[0], "/")
	return s[0], s[1], args[1:]
}
开发者ID:seikichi,项目名称:gopl,代码行数:8,代码来源:issues.go

示例13: Missing

func Missing(flags *flag.FlagSet, values ...string) {
	for _, value := range values {
		if value != "" {
			continue
		}
		flags.Usage()
		os.Exit(0)
	}
}
开发者ID:paultag,项目名称:descend,代码行数:9,代码来源:main.go

示例14: Run

func (c *ListCommand) Run(args []string) int {
	var format string
	var err error
	var secret *api.Secret
	var flags *flag.FlagSet
	flags = c.Meta.FlagSet("list", meta.FlagSetDefault)
	flags.StringVar(&format, "format", "table", "")
	flags.Usage = func() { c.Ui.Error(c.Help()) }
	if err := flags.Parse(args); err != nil {
		return 1
	}

	args = flags.Args()
	if len(args) != 1 || len(args[0]) == 0 {
		c.Ui.Error("read expects one argument")
		flags.Usage()
		return 1
	}

	path := args[0]
	if path[0] == '/' {
		path = path[1:]
	}

	if !strings.HasSuffix(path, "/") {
		path = path + "/"
	}

	client, err := c.Client()
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error initializing client: %s", err))
		return 2
	}

	secret, err = client.Logical().List(path)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error reading %s: %s", path, err))
		return 1
	}
	if secret == nil {
		c.Ui.Error(fmt.Sprintf(
			"No value found at %s", path))
		return 1
	}
	if secret.WrapInfo != nil && secret.WrapInfo.TTL != 0 {
		return OutputSecret(c.Ui, format, secret)
	}

	if secret.Data["keys"] == nil {
		c.Ui.Error("No entries found")
		return 0
	}

	return OutputList(c.Ui, format, secret)
}
开发者ID:quixoten,项目名称:vault,代码行数:57,代码来源:list.go

示例15: Run

func (c *UnwrapCommand) Run(args []string) int {
	var format string
	var field string
	var err error
	var secret *api.Secret
	var flags *flag.FlagSet
	flags = c.Meta.FlagSet("unwrap", meta.FlagSetDefault)
	flags.StringVar(&format, "format", "table", "")
	flags.StringVar(&field, "field", "", "")
	flags.Usage = func() { c.Ui.Error(c.Help()) }
	if err := flags.Parse(args); err != nil {
		return 1
	}

	args = flags.Args()
	if len(args) != 1 || len(args[0]) == 0 {
		c.Ui.Error("Unwrap expects one argument: the ID of the wrapping token")
		flags.Usage()
		return 1
	}

	tokenID := args[0]
	_, err = uuid.ParseUUID(tokenID)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Given token could not be parsed as a UUID: %s", err))
		return 1
	}

	client, err := c.Client()
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error initializing client: %s", err))
		return 2
	}

	secret, err = client.Logical().Unwrap(tokenID)
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}
	if secret == nil {
		c.Ui.Error("Secret returned was nil")
		return 1
	}

	// Handle single field output
	if field != "" {
		return PrintRawField(c.Ui, secret, field)
	}

	return OutputSecret(c.Ui, format, secret)
}
开发者ID:citywander,项目名称:vault,代码行数:53,代码来源:unwrap.go


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