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
|
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"fmt"
"io"
"git.labunix.xyz/krino/internal/engine"
"git.labunix.xyz/krino/internal/xdg"
)
func init() { commands["check"] = cmdCheck }
// cmdCheck validates the configuration and lists each directory's rules,
// its current state, and the extractors available for content tests.
func cmdCheck(g *globals, args []string, stdout, stderr io.Writer) int {
fs := flagSet("check", g)
if code, ok := parse(fs, args, stdout, stderr); !ok {
return code
}
if g.minAgeSet {
return usageError(stderr, "--min-age applies only to sorting and explain")
}
if code, refused := refuseUnusedFlags(g, stderr, "check", false); refused {
return code
}
e, errs := engine.Load(mainFile(g), fs.Args()...)
if len(errs) > 0 {
printDiags(stderr, errs)
return 2
}
r := e.Check()
fmt.Fprintf(stdout, "config: %s\n", display(xdg.Abbrev(r.MainFile)))
fmt.Fprintf(stdout, "log: %s\n", display(xdg.Abbrev(r.LogFile)))
fmt.Fprintf(stdout, "cache: %s\n", display(xdg.Abbrev(cacheDir())))
if len(r.Dirs) == 0 {
fmt.Fprintln(stdout, "no directories included; add one with: krino new NAME PATH")
}
for _, dr := range r.Dirs {
fmt.Fprintf(stdout, "\n%s %s\n", display(dr.Dir.Name), display(xdg.Abbrev(dr.Dir.Root)))
if dr.Missing {
fmt.Fprintf(stdout, " warning: %s is not a directory right now; it will be skipped\n", display(xdg.Abbrev(dr.Dir.Root)))
}
for _, x := range dr.Dir.Excludes {
fmt.Fprintf(stdout, " %s\n", display(x.Text))
}
if len(dr.Dir.Rules) == 0 {
fmt.Fprintln(stdout, " no rules yet")
}
for i, rule := range dr.Dir.Rules {
fmt.Fprintf(stdout, " %2d %-16s %s\n", i+1, display(rule.Name), display(describeActions(rule.Conf)))
}
}
fmt.Fprintln(stdout, "\nextractors:")
for _, tool := range r.Tools {
path := "not installed"
if tool.Path != "" {
path = xdg.Abbrev(tool.Path)
}
fmt.Fprintf(stdout, " %-9s %s\n", tool.Name, path)
}
return 0
}
|