本文整理匯總了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()
}
}
示例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
}
示例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()
}
示例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)
}
示例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)
}
示例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()
}
示例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)
}
}
示例8: usg
func usg(msg string, fs *flag.FlagSet) func() {
return func() {
fmt.Fprintf(os.Stderr, msg)
fs.PrintDefaults()
os.Exit(2)
}
}
示例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, " "))
}
示例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)
}
示例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)
}
}
示例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()
}
}
示例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)
}
示例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()
}
}
}
示例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()
}
}