MCPcopy Create free account
hub / github.com/bracesdev/errtrace / Parse

Method Parse

cmd/errtrace/main.go:89–119  ·  view source on GitHub ↗
(w io.Writer, args []string)

Source from the content-addressed store, hash-verified

87}
88
89func (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.
122type format int

Callers 3

TestParseMainParamsFunction · 0.95
RunMethod · 0.95
TestParseFormatFlagFunction · 0.45

Calls 2

WrapFunction · 0.92
loglnFunction · 0.85

Tested by 2

TestParseMainParamsFunction · 0.76
TestParseFormatFlagFunction · 0.36