aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/new.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-11 14:47:10 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-11 15:01:57 +0200
commit42b02c47be9b285099203e44a2570636d4ca6f03 (patch)
tree82bcb9e19bd886f36e1ca7b2d94a204c988f1fd1 /cmd/krino/new.go
downloadkrino-42b02c47be9b285099203e44a2570636d4ca6f03.tar.gz
krino-42b02c47be9b285099203e44a2570636d4ca6f03.zip
krino: foundation — sexp reader, config language, init/new/check
Diffstat (limited to 'cmd/krino/new.go')
-rw-r--r--cmd/krino/new.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/cmd/krino/new.go b/cmd/krino/new.go
new file mode 100644
index 0000000..1cd89a6
--- /dev/null
+++ b/cmd/krino/new.go
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package main
+
+import (
+ "fmt"
+ "io"
+
+ "krino/internal/config"
+ "krino/internal/xdg"
+)
+
+func init() { commands["new"] = cmdNew }
+
+// cmdNew creates dirs/NAME.conf from the template and includes it.
+func cmdNew(g *globals, args []string, stdout, stderr io.Writer) int {
+ fs := flagSet("new", g)
+ if code, ok := parse(fs, args, stdout, stderr); !ok {
+ return code
+ }
+ if fs.NArg() != 2 {
+ return usageError(stderr, "usage: krino new NAME PATH")
+ }
+ name := fs.Arg(0)
+ file, err := config.NewDir(mainFile(g), name, fs.Arg(1))
+ if err != nil {
+ fmt.Fprintf(stderr, "krino: %v\n", err)
+ return 2
+ }
+ fmt.Fprintf(stdout, "created %s and added %q to include\n", xdg.Abbrev(file), name)
+ fmt.Fprintf(stdout, "edit its rules, then check them with: krino check %s\n", name)
+ return 0
+}