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

Method Run

cmd/errtrace/main.go:188–246  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

186}
187
188func (cmd *mainCmd) Run(args []string) (exitCode int) {
189 cmd.log = log.New(cmd.Stderr, "", 0)
190
191 if exitCode, ok := cmd.handleToolExec(args); ok {
192 return exitCode
193 }
194
195 var p mainParams
196 if err := p.Parse(cmd.Stderr, args); err != nil {
197 if errors.Is(err, flag.ErrHelp) {
198 return 0
199 }
200 cmd.log.Printf("errtrace: %+v", err)
201 return 1
202 }
203
204 files, err := expandPatterns(p.Patterns)
205 if err != nil {
206 cmd.log.Printf("errtrace: %+v", err)
207 return 1
208 }
209
210 // Paths will be printed relative to CWD.
211 // Paths outside it will be printed as-is.
212 var workDir string
213 if wd, err := os.Getwd(); err == nil {
214 workDir = wd + string(filepath.Separator)
215 }
216
217 for _, file := range files {
218 display := file
219 if workDir != "" {
220 // Not using filepath.Rel
221 // because we don't want any ".."s in the path.
222 display = strings.TrimPrefix(file, workDir)
223 }
224 if display == "-" {
225 display = "stdin"
226 }
227
228 req := fileRequest{
229 Format: p.shouldFormat(),
230 Write: p.Write,
231 List: p.List,
232 Filename: display,
233 Filepath: file,
234 ImplicitStdin: p.ImplicitStdin,
235 RewriteOpts: rewriteOpts{
236 NoWrapN: p.NoWrapN,
237 },
238 }
239 if err := cmd.processFile(req); err != nil {
240 cmd.log.Printf("%s:%+v", display, err)
241 exitCode = 1
242 }
243 }
244
245 return exitCode

Callers 15

mainFunction · 0.95
TestFormatVerbsFunction · 0.80
TestFormatFunction · 0.80
TestUnwrapFrameFunction · 0.80
TestWriteTreeFunction · 0.80
TestWrap_LineFunction · 0.80
toolExecVersionMethod · 0.80
runOriginalMethod · 0.80
TestToolExecFunction · 0.80
runGoFunction · 0.80
TestErrHelpFunction · 0.80
TestGoldenFunction · 0.80

Calls 5

handleToolExecMethod · 0.95
ParseMethod · 0.95
shouldFormatMethod · 0.95
processFileMethod · 0.95
expandPatternsFunction · 0.85

Tested by 15

TestFormatVerbsFunction · 0.64
TestFormatFunction · 0.64
TestUnwrapFrameFunction · 0.64
TestWriteTreeFunction · 0.64
TestWrap_LineFunction · 0.64
TestToolExecFunction · 0.64
runGoFunction · 0.64
TestErrHelpFunction · 0.64
TestGoldenFunction · 0.64
testGoldenFileFunction · 0.64
testGoldenContentsFunction · 0.64
TestParseMainParamsFunction · 0.64