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
|
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"fmt"
"io"
"git.labunix.xyz/krino/internal/config"
"git.labunix.xyz/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 g.minAgeSet {
return usageError(stderr, "--min-age applies only to sorting and explain")
}
if code, refused := refuseUnusedFlags(g, stderr, "new", false); refused {
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", display(xdg.Abbrev(file)), name)
fmt.Fprintf(stdout, "edit its rules, then check them with: krino check %s\n", name)
return 0
}
|