-
Notifications
You must be signed in to change notification settings - Fork 148
/
main.go
68 lines (56 loc) · 1.55 KB
/
main.go
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
package main
import (
"flag"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
var inputFiles, xxxTags string
var removeTagComment bool
flag.StringVar(&inputFiles, "input", "", "pattern to match input file(s)")
flag.StringVar(&xxxTags, "XXX_skip", "", "tags that should be skipped (applies 'tag:\"-\"') for unknown fields (deprecated since protoc-gen-go v1.4.0)")
flag.BoolVar(&removeTagComment, "remove_tag_comment", false, "removes tag comments from the generated file(s)")
flag.BoolVar(&verbose, "verbose", false, "verbose logging")
flag.Parse()
var xxxSkipSlice []string
if len(xxxTags) > 0 {
logf("warn: deprecated flag '-XXX_skip' used")
xxxSkipSlice = strings.Split(xxxTags, ",")
}
if inputFiles == "" {
log.Fatal("input file is mandatory, see: -help")
}
// Note: glob doesn't handle ** (treats as just one *). This will return
// files and folders, so we'll have to filter them out.
globResults, err := filepath.Glob(inputFiles)
if err != nil {
log.Fatal(err)
}
var matched int
for _, path := range globResults {
finfo, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
if finfo.IsDir() {
continue
}
// It should end with ".go" at a minimum.
if !strings.HasSuffix(strings.ToLower(finfo.Name()), ".go") {
continue
}
matched++
areas, err := parseFile(path, nil, xxxSkipSlice)
if err != nil {
log.Fatal(err)
}
if err = writeFile(path, areas, removeTagComment); err != nil {
log.Fatal(err)
}
}
if matched == 0 {
log.Fatalf("input %q matched no files, see: -help", inputFiles)
}
}