-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo-notes.go
More file actions
71 lines (61 loc) · 1.58 KB
/
go-notes.go
File metadata and controls
71 lines (61 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/cthulhu/go-notes/parser"
"github.com/cthulhu/go-notes/scanner"
)
var usage = `Usage: go-notes [flags] <Go file or directory> ...
Without options generates all the note types. Default are:
// FIXME - call to fix something
// OPTIMIZE - call for a refactoring
// TODO - future plans
Options:
-f - FIXME annotations
-o - OPTIMIZE annotations
-t - TODO annotations
-c CUSTOM - custom annotation label
-format count - output format aggregated counts
-format list - output format list with files and annotations (default)
`
var (
fixme = flag.Bool("f", false, "FIXME annotations")
optimize = flag.Bool("o", false, "OPTIMIZE annotations")
todo = flag.Bool("t", false, "TODO annotations")
custom = flag.String("c", "", "custom annotation, for example BUG or BAD SMELL")
format = flag.String("format", "list", "output format")
)
func main() {
flag.Usage = func() { fmt.Fprint(os.Stderr, usage) }
flag.Parse()
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
paths, scannerErrors := scanner.New(ctx, args)
p := parser.New(*fixme, *todo, *optimize, *custom, *format)
filesLoop:
for {
select {
case file := <-paths:
if file == "" {
break filesLoop
}
exitIfError(p.Parse(file))
case err := <-scannerErrors:
exitIfError(err)
}
}
fmt.Println(p.Aggregate())
}
func exitIfError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "Error running go-notes: %v", err)
os.Exit(1)
}
}