-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 943 Bytes
/
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
package main
import (
"log"
"os"
"strings"
"github.com/THE108/enumlinter/logger"
"golang.org/x/tools/go/loader"
)
const (
typeToCheckFlagName = "-type"
)
func parseArgs() (typeToCheck string, pkgpaths []string, ok bool) {
if len(os.Args) < 3 {
return
}
if os.Args[1] == typeToCheckFlagName {
typeToCheck = os.Args[2]
pkgpaths = os.Args[3:]
ok = true
return
}
if prefix := typeToCheckFlagName + "="; strings.HasPrefix(os.Args[1], prefix) {
typeToCheck = strings.TrimPrefix(os.Args[1], prefix)
pkgpaths = os.Args[2:]
ok = true
return
}
return
}
func main() {
typeToCheck, pkgpaths, ok := parseArgs()
if !ok {
log.Fatalf("Usage: enumlinter -type <enumerated type> <args>\n%s",
"<enumerated type> is an enumerated type to check."+loader.FromArgsUsage)
}
if err := run(pkgpaths, typeToCheck, logger.NewLogger(os.Stdout)); err != nil {
log.Fatalf("Can't load prog from args: %s", err.Error())
}
}