-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
86 lines (76 loc) · 1.53 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
"os"
p "path/filepath"
"strings"
)
var version = `0.3.0`
var (
verbose = flag.Bool("v", false, "verbose output")
showversion = flag.Bool("version", false, "show version information")
)
func verb(f string, a ...interface{}) {
if *verbose {
fmt.Fprintf(os.Stderr, f, a...)
}
}
func main() {
flag.Parse()
files := flag.Args()
if *showversion {
fmt.Printf("golint %s\n", version)
return
}
verb("Scanning for source files... ")
if len(files) == 0 {
// just use the current directory if no files were specified
files = make([]string, 1)
files[0] = "."
}
srcs := make([]string, 0)
for _, fname := range files {
srcs = append(srcs, listFiles(fname, ".go")...)
}
verb("\n")
for _, sf := range srcs {
f, err := os.Open(sf)
if err != nil {
fmt.Fprintf(os.Stderr, " ! %s\n", sf)
continue
}
PrintLex(f)
f.Close()
}
}
func listFiles(fname string, suf string) (fs []string) {
info, err := os.Stat(fname)
if err != nil {
return
}
if info.IsDir() {
f, _ := os.Open(fname)
dn, _ := f.Readdirnames(-1)
for _, filename := range dn {
if filename[0] == '.' {
continue
}
filename = p.Join(fname, filename)
info, err := os.Stat(filename)
if err != nil {
continue
}
if info.IsDir() {
fs = append(fs, listFiles(filename, suf)...)
} else if strings.HasSuffix(filename, suf) {
verb("%s ", filename)
fs = append(fs, filename)
}
}
} else if strings.HasSuffix(fname, suf) {
verb("%s", fname)
fs = append(fs, fname)
}
return
}