diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-11 14:47:10 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-11 15:01:57 +0200 |
| commit | 42b02c47be9b285099203e44a2570636d4ca6f03 (patch) | |
| tree | 82bcb9e19bd886f36e1ca7b2d94a204c988f1fd1 /cmd/krino/check.go | |
| download | krino-42b02c47be9b285099203e44a2570636d4ca6f03.tar.gz krino-42b02c47be9b285099203e44a2570636d4ca6f03.zip | |
krino: foundation — sexp reader, config language, init/new/check
Diffstat (limited to 'cmd/krino/check.go')
| -rw-r--r-- | cmd/krino/check.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cmd/krino/check.go b/cmd/krino/check.go new file mode 100644 index 0000000..fcd507d --- /dev/null +++ b/cmd/krino/check.go @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "fmt" + "io" + "os" + + "krino/internal/config" + "krino/internal/xdg" +) + +func init() { commands["check"] = cmdCheck } + +// cmdCheck validates the configuration and lists each directory's rules. +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 + } + cfg, errs := config.Load(mainFile(g), fs.Args()...) + if len(errs) > 0 { + printDiags(stderr, errs) + return 2 + } + fmt.Fprintf(stdout, "config: %s\n", xdg.Abbrev(cfg.Main.File)) + if len(cfg.Dirs) == 0 { + fmt.Fprintln(stdout, "no directories included; add one with: krino new NAME PATH") + } + for _, d := range cfg.Dirs { + fmt.Fprintf(stdout, "\n%s %s\n", d.Name, xdg.Abbrev(d.Path)) + if fi, err := os.Stat(d.Path); err != nil || !fi.IsDir() { + fmt.Fprintf(stdout, " warning: %s is not a directory right now; it will be skipped\n", xdg.Abbrev(d.Path)) + } + if len(d.Rules) == 0 { + fmt.Fprintln(stdout, " no rules yet") + } + for i, r := range d.Rules { + fmt.Fprintf(stdout, " %2d %-16s %s\n", i+1, r.Name, describeActions(r)) + } + } + return 0 +} |
