-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (60 loc) · 1.3 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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"github.com/LevInteractive/qa/document"
"github.com/LevInteractive/qa/scanner"
"github.com/LevInteractive/qa/transform"
"github.com/LevInteractive/qa/transform/csv"
)
var helptxt = `
qa [dir] > output-file.csv
Full Documentation: https://github.com/LevInteractive/qa/blob/master/README.md
`
func main() {
helpMode := flag.Bool("h", false, "help")
flag.Parse()
if *helpMode == true {
fmt.Println(helptxt)
return
}
var dir string
if len(flag.Args()) == 0 {
fmt.Println(helptxt)
return
}
dir = flag.Args()[0]
files := List(dir)
config := scanner.Config{
AllowLinebreaks: false,
}
documents := make(document.Documents, 0)
for _, file := range files {
dat, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
}
documents = append(documents, scanner.Scan(string(dat), config))
}
groups := transform.Make(documents)
csv.Gen(groups)
}
// List all .qa files in a directory.
func List(dir string) []string {
extRe := regexp.MustCompile("\\.qa$")
fileList := make([]string, 0)
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if extRe.MatchString(path) {
fileList = append(fileList, path)
}
return err
})
if err != nil {
panic(err)
}
return fileList
}