本文整理汇总了Golang中flag.FlagSet.SetOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.SetOutput方法的具体用法?Golang FlagSet.SetOutput怎么用?Golang FlagSet.SetOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.SetOutput方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例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: 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)
}
示例4: 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()
}
示例5: initUsage
func initUsage(fs *flag.FlagSet) {
fmt.Println("usage: git-bzr-bridge init [-h] <path>")
fmt.Println("\nflags:")
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
fmt.Print(`
init will initialize a new repository at <path>
`)
}
示例6: updateHookUsage
func updateHookUsage(fs *flag.FlagSet) {
fmt.Println("usage: git-bzr-bridge update-hook [-h] <ref name> <old obj> <new obj>")
fmt.Println("\nflags:")
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
fmt.Print(`
update
`)
}
示例7: branchesUsage
func branchesUsage(fs *flag.FlagSet) {
fmt.Println("usage: git-bzr-bridge branches [-h] [-v]")
fmt.Println("\nflags:")
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
fmt.Print(`
branches will list all branches known to git-bzr-bridge. Default output
format will list git branch references one per line. If -v is specified
it will also show Bzr urls and names of the (hidden) bzr branches.
`)
}
示例8: parseArgs
// parseArgs parses cli arguments. This caters for parsing extra flags to caddy.
func parseArgs() (cliArgs, error) {
args := cliArgs{conf: configFileName, source: "."}
fs := flag.FlagSet{}
fs.SetOutput(ioutil.Discard)
h := false
fs.StringVar(&args.conf, "c", args.conf, "")
fs.StringVar(&args.conf, "conf", args.conf, "")
fs.StringVar(&args.after, "a", args.after, "")
fs.StringVar(&args.after, "after", args.after, "")
fs.StringVar(&args.source, "s", args.source, "")
fs.StringVar(&args.source, "source", args.source, "")
fs.StringVar(&args.output, "o", args.output, "")
fs.StringVar(&args.output, "output", args.output, "")
fs.BoolVar(&args.update, "u", args.update, "")
fs.BoolVar(&args.update, "update", args.update, "")
fs.BoolVar(&h, "h", h, "")
fs.BoolVar(&h, "help", h, "")
err := fs.Parse(os.Args[1:])
if h || err != nil {
return args, fmt.Errorf(usage)
}
if fs.NArg() > 0 {
args.directive = fs.Arg(0)
}
// extract caddy and go args
if fs.NArg() > 1 {
remArgs := fs.Args()[1:]
for i, arg := range remArgs {
if arg == "go" {
if len(remArgs) > i+1 {
args.goArgs = remArgs[i+1:]
}
break
}
args.caddyArgs = append(args.caddyArgs, arg)
}
}
if err := addJSONConf(&args); err != nil {
return args, err
}
if args.directive == "" {
return args, usageError(fmt.Errorf("directive not set."))
}
return args, err
}
示例9: PrintDefaults
func PrintDefaults(flag *Flag.FlagSet) {
var into bytes.Buffer
flag.SetOutput(&into)
flag.PrintDefaults()
outfrom := bufio.NewReader(&into)
for {
line, err := outfrom.ReadString('\n')
if err != nil {
break
}
if strings.HasSuffix(line, ": \x00\n") {
continue
}
fmt.Fprint(os.Stderr, line)
}
}
示例10: showUsage
func showUsage(fs *flag.FlagSet) {
fmt.Println("usage: git-bzr-bridge [flags] <command> [<args>]")
fmt.Println("\nflags:")
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
// get a list of all commands and sort them
cmds := make([]string, 0, len(commands))
for k := range commands {
cmds = append(cmds, k)
}
sort.Strings(cmds)
fmt.Println("\ncommands:")
for _, k := range cmds {
fmt.Printf(" %-12s %s\n", k, commands[k].description)
}
fmt.Println("\nRun 'git-bzr-bridge <command> -h' to get usage message for <command>")
}
示例11: flagSetPrintUsage
func flagSetPrintUsage(fl flag.FlagSet, w io.Writer, progname string) {
fmt.Fprintf(w, "Usage of %s:\n", progname)
fl.SetOutput(w)
fl.PrintDefaults()
}