| 87 | } |
| 88 | |
| 89 | func (p *mainParams) Parse(w io.Writer, args []string) error { |
| 90 | flag := flag.NewFlagSet("errtrace", flag.ContinueOnError) |
| 91 | flag.SetOutput(w) |
| 92 | flag.Usage = func() { |
| 93 | logln(w, "usage: errtrace [options] <source files | patterns>") |
| 94 | flag.PrintDefaults() |
| 95 | } |
| 96 | |
| 97 | flag.Var(&p.Format, "format", "whether to format ouput; one of: [auto, always, never].\n"+ |
| 98 | "auto is the default and will format if the output is being written to a file.") |
| 99 | flag.BoolVar(&p.Write, "w", false, |
| 100 | "write result to the given source files instead of stdout.") |
| 101 | flag.BoolVar(&p.List, "l", false, |
| 102 | "list files that would be modified without making any changes.") |
| 103 | flag.BoolVar(&p.NoWrapN, "no-wrapn", false, |
| 104 | "wrap multiple return values without using errtrace.WrapN", |
| 105 | ) |
| 106 | |
| 107 | if err := flag.Parse(args); err != nil { |
| 108 | return errtrace.Wrap(err) |
| 109 | } |
| 110 | |
| 111 | p.Patterns = flag.Args() |
| 112 | if len(p.Patterns) == 0 { |
| 113 | // Read file from stdin when there's no args, similar to gofmt. |
| 114 | p.Patterns = []string{"-"} |
| 115 | p.ImplicitStdin = true |
| 116 | } |
| 117 | |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | // format specifies whether the output should be gofmt'd. |
| 122 | type format int |