/
proto_path.go
45 lines (36 loc) · 868 Bytes
/
proto_path.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
package grpcdump
import (
"os"
"path/filepath"
"strings"
"path"
"log"
)
type ArrayFlags []string
func (arrayFlags *ArrayFlags) String() string {
return "Specify the directory in which to search for imports"
}
func (arrayFlags *ArrayFlags) Set(value string) error {
*arrayFlags = append(*arrayFlags, value)
return nil
}
func (arrayFlags *ArrayFlags) ParseDir(suffix string) []string {
ret := make([]string, 0)
for _, file := range *arrayFlags {
fileinfo, _ := os.Stat(file)
if fileinfo.IsDir() {
filepath.Walk(file, func(p string, info os.FileInfo, err error) error {
if strings.HasSuffix(info.Name(), suffix) {
f := path.Join(file, info.Name())
log.Printf("proto files: %s", f)
ret = append(ret, f)
}
return nil
})
} else {
log.Printf("proto files: %s", file)
ret = append(ret, file)
}
}
return ret
}