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/common.go | |
| download | krino-42b02c47be9b285099203e44a2570636d4ca6f03.tar.gz krino-42b02c47be9b285099203e44a2570636d4ca6f03.zip | |
krino: foundation — sexp reader, config language, init/new/check
Diffstat (limited to 'cmd/krino/common.go')
| -rw-r--r-- | cmd/krino/common.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cmd/krino/common.go b/cmd/krino/common.go new file mode 100644 index 0000000..ea1e83d --- /dev/null +++ b/cmd/krino/common.go @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "fmt" + "io" + "strings" + + "krino/internal/config" + "krino/internal/xdg" +) + +// mainFile is -c FILE, or the default krino.conf. +func mainFile(g *globals) string { + if g.conf != "" { + return xdg.Expand(g.conf) + } + return config.DefaultFile() +} + +// usageError reports a command-line mistake and returns exit status 2. +func usageError(stderr io.Writer, msg string) int { + fmt.Fprintf(stderr, "krino: %s\nrun 'krino -h' for help\n", msg) + return 2 +} + +// printDiags prints config problems with ~ for the home directory, then a count. +func printDiags(stderr io.Writer, errs []*config.Diag) { + for _, e := range errs { + d := *e + d.File = xdg.Abbrev(d.File) + fmt.Fprintln(stderr, &d) + } + if len(errs) == 1 { + fmt.Fprintln(stderr, "krino: 1 problem found") + } else { + fmt.Fprintf(stderr, "krino: %d problems found\n", len(errs)) + } +} + +// describeActions renders a rule's actions briefly, as in: move PDF, stop. +func describeActions(r *config.Rule) string { + var parts []string + for _, a := range r.Actions { + if a.Arg == "" { + parts = append(parts, a.Kind.String()) + } else { + parts = append(parts, a.Kind.String()+" "+a.Arg) + } + } + if r.Stop { + parts = append(parts, "stop") + } + return strings.Join(parts, ", ") +} |
