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


Golang FlagSet.PrintDefaults方法代码示例

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


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

示例1: createComponentUsage

// CreateComponentUsage creates a usage function for a component.
func createComponentUsage(info pythia.ComponentInfo, fs *flag.FlagSet) func() {
	return func() {
		fmt.Fprintf(os.Stderr, componentUsageHeader, os.Args[0], info.Name,
			info.Description)
		fs.PrintDefaults()
	}
}
开发者ID:ChrisKun,项目名称:pythia,代码行数:8,代码来源:config.go

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

示例3: runAddBeer

func runAddBeer(command string, flags *flag.FlagSet, id string, date string, size string, days string, years string, count string, cellar *BeerCellar) {
	if command == "add" {
		if id != "" {
			if date == "" {
				date = time.Now().Format("02/01/06")
			}

			log.Printf("HERE %v and %v\n", days, years)

			if days != "" {
				cellar.AddBeerByDays(id, date, size, days, count)
				cellar.PrintCellar(&StdOutPrint{})
			} else if years != "" {
				log.Printf("ADDING BY YEARS\n")
				cellar.AddBeerByYears(id, date, size, years, count)
				cellar.PrintCellar(&StdOutPrint{})
			} else {
				box := cellar.AddBeer(id, date, size)
				print := &StdOutPrint{}
				box.PrintCellar(print)
			}
		} else {
			flags.SetOutput(os.Stdout)
			flags.PrintDefaults()
		}
	}

	cellar.printDiff()
}
开发者ID:brotherlogic,项目名称:beer,代码行数:29,代码来源:BeerCellar.go

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

示例5: commandWorker

func commandWorker(wi *Instance, wr *wrangler.Wrangler, args []string, cell string, runFromCli bool) (Worker, error) {
	action := args[0]

	actionLowerCase := strings.ToLower(action)
	for _, group := range commands {
		for _, cmd := range group.Commands {
			if strings.ToLower(cmd.Name) == actionLowerCase {
				var subFlags *flag.FlagSet
				if runFromCli {
					subFlags = flag.NewFlagSet(action, flag.ExitOnError)
				} else {
					subFlags = flag.NewFlagSet(action, flag.ContinueOnError)
				}
				// The command may be run from an RPC and may not log to the console.
				// The Wrangler logger defines where the output has to go.
				subFlags.SetOutput(logutil.NewLoggerWriter(wr.Logger()))
				subFlags.Usage = func() {
					wr.Logger().Printf("Usage: %s %s %s\n\n", os.Args[0], cmd.Name, cmd.Params)
					wr.Logger().Printf("%s\n\n", cmd.Help)
					subFlags.PrintDefaults()
				}
				return cmd.Method(wi, wr, subFlags, args[1:])
			}
		}
	}
	if runFromCli {
		flag.Usage()
	} else {
		PrintAllCommands(wr.Logger())
	}
	return nil, fmt.Errorf("unknown command: %v", action)
}
开发者ID:jmptrader,项目名称:vitess,代码行数:32,代码来源:command.go

示例6: Usage

// Usage returns a usage documentation of a command.
func (c Command) Usage(flags *flag.FlagSet) string {
	usage := fmt.Sprintf("Usage: %s", c.Long)

	if flags == nil {
		return usage
	}

	var hasFlag bool
	flags.VisitAll(func(_ *flag.Flag) {
		hasFlag = true
	})

	if hasFlag == false {
		return usage
	}

	buf := bytes.NewBufferString(usage)
	buf.WriteString("\n\nOptions:\n")

	defer flags.SetOutput(nil)
	flags.SetOutput(buf)

	flags.PrintDefaults()

	return buf.String()
}
开发者ID:yuuki,项目名称:go-cli,代码行数:27,代码来源:cli.go

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

示例8: usg

func usg(msg string, fs *flag.FlagSet) func() {
	return func() {
		fmt.Fprintf(os.Stderr, msg)
		fs.PrintDefaults()
		os.Exit(2)
	}
}
开发者ID:kevinburke,项目名称:hostsfile,代码行数:7,代码来源:cmd.go

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

示例10: usage

func usage(err error, myflags *flag.FlagSet) {
	fmt.Fprintf(os.Stderr, "%s\n", err)

	fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
	myflags.PrintDefaults()
	os.Exit(1)
}
开发者ID:glycerine,项目名称:tmframe,代码行数:7,代码来源:archiver.go

示例11: setUsage

func setUsage(fs *flag.FlagSet) {
	fs.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fs.PrintDefaults()
		os.Exit(2)
	}
}
开发者ID:sdaros,项目名称:passgo,代码行数:7,代码来源:cli.go

示例12: printHelp

// Returns a function that will print a help string
func printHelp(flags *flag.FlagSet) func() {
	return func() {
		fmt.Printf("usage: %s [--in=INPUT_IMAGE] [--out=OUTPUT_IMAGE] [options]\n", os.Args[0])

		fmt.Printf("\nOptions:\n")
		flags.PrintDefaults()
	}
}
开发者ID:prsteele,项目名称:circapprox,代码行数:9,代码来源:filter.go

示例13: printUsageAndExit

func printUsageAndExit(message string, flagSet *flag.FlagSet) {
	stderr.Printf("%s\n\n", message)
	stderr.Println("usage: confab COMMAND OPTIONS\n")
	stderr.Println("COMMAND: \"start\" or \"stop\"")
	stderr.Println("\nOPTIONS:")
	flagSet.PrintDefaults()
	stderr.Println()
	os.Exit(1)
}
开发者ID:Tier3,项目名称:consul-release,代码行数:9,代码来源:main.go

示例14: runListBeers

func runListBeers(command string, flags *flag.FlagSet, numBombers int, numSmall int, cellar *BeerCellar) {
	if command == "list" {
		if flags.Parsed() {
			cellar.PrintBeers(numBombers, numSmall)
		} else {
			flags.PrintDefaults()
		}
	}
}
开发者ID:brotherlogic,项目名称:beer,代码行数:9,代码来源:BeerCellar.go

示例15: UsageFunc

func UsageFunc(fs *flag.FlagSet) func() {
	return func() {
		// default usage
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fs.PrintDefaults() // flag.PrintDefaults()
		// continued usage:
		newHelp(os.Stderr).Run()
	}
}
开发者ID:vadv,项目名称:ostent,代码行数:9,代码来源:help.go


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