-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.23 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
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"github.com/GuanceCloud/mdcheck/check"
)
var (
autofix,
jsonOutput bool
markdownDir,
metaDir string
)
//nolint:gochecknoinits
func init() {
flag.StringVar(&markdownDir, "md-dir", "", "markdown dirs")
flag.StringVar(&metaDir, "meta-dir", "", "markdown meta dir, with meta dir set, only checking meta info of markdown")
flag.BoolVar(&autofix, "autofix", false, "auto fix error")
flag.BoolVar(&jsonOutput, "json", false, "set output in json format(2 space indent)")
}
func main() {
flag.Parse()
log.SetFlags(log.Lshortfile | log.LstdFlags)
if markdownDir != "" {
res, err := check.Check(
check.WithMarkdownDir(markdownDir),
check.WithMetaDir(metaDir),
check.WithAutofix(autofix),
)
if err != nil {
log.Printf("[E] %s", err.Error())
return
}
if jsonOutput {
if j, err := json.MarshalIndent(res, "", " "); err != nil {
log.Printf("[E] json.MarshalIndent: %s", err.Error())
} else {
fmt.Printf("%s", string(j))
}
} else {
for _, r := range res {
switch {
case r.Err != "":
fmt.Printf("%s: %q | Err: %s\n", r.Path, r.Text, r.Err)
case r.Warn != "":
fmt.Printf("%s: Warn: %s\n", r.Path, r.Warn)
}
}
}
}
}