Skip to content

Commit

Permalink
make sure defer runs (linter) (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado authored Sep 11, 2020
1 parent f64f119 commit 421d720
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,16 @@ func convertCoverage(in io.Reader, out io.Writer) error {
}

func main() {
os.Exit(gcovmain())
}

func gcovmain() int {
infileName := flag.String("infile", "", "go coverage file to read, default: <stdin>")
outfileName := flag.String("outfile", "", "lcov file to write, default: <stdout>")
flag.Parse()
if len(flag.Args()) > 0 {
flag.Usage()
os.Exit(1)
return 1
}

infile := os.Stdin
Expand All @@ -253,20 +257,24 @@ func main() {
if *infileName != "" {
infile, err = os.Open(*infileName)
if err != nil {
log.Fatalf("error opening input file: %v", err)
log.Printf("error opening input file: %v\n", err)
return 2
}
defer infile.Close()
}
if *outfileName != "" {
outfile, err = os.Create(*outfileName)
if err != nil {
log.Fatalf("error opening output file: %v", err)
log.Printf("error opening output file: %v\n", err)
return 3
}
defer outfile.Close()
}

err = convertCoverage(infile, outfile)
if err != nil {
log.Fatalf("convert: %v", err)
log.Printf("error: convert: %v", err)
return 4
}
return 0
}

0 comments on commit 421d720

Please sign in to comment.