// SPDX-License-Identifier: GPL-3.0-or-later package main import ( "fmt" "io" "krino/internal/engine" "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") } 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 }