-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
77 lines (63 loc) · 1.77 KB
/
new.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cmd
import (
"fmt"
"os"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
"github.com/midoks/zzz/internal/tools"
)
var New = cli.Command{
Name: "new",
Usage: "create zzz file",
Description: `create zzz configuration file`,
Action: CmdNew,
Flags: []cli.Flag{},
}
// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type ZZZ struct {
Title string
Frequency int64
DirFilter []string
Ext []string
EnableRun bool
Action struct {
Before []string `yaml:"before"`
After []string `yaml:"after"`
Exit []string `yaml:"exit"`
}
Link string
}
const Zfile = ".zzz.yaml"
func CmdNew(c *cli.Context) error {
rootPath, _ := os.Getwd()
file := rootPath + "/" + Zfile
if tools.IsExist(file) {
fmt.Println("configuration file is exist!")
} else {
conf := ZZZ{}
conf.Title = "zzz"
conf.Ext = append(conf.Ext, "go")
conf.Frequency = 3
conf.EnableRun = true
conf.DirFilter = append(conf.DirFilter, "tmp")
conf.DirFilter = append(conf.DirFilter, ".git")
conf.DirFilter = append(conf.DirFilter, "public")
conf.DirFilter = append(conf.DirFilter, "scripts")
conf.DirFilter = append(conf.DirFilter, "vendor")
conf.DirFilter = append(conf.DirFilter, "logs")
conf.DirFilter = append(conf.DirFilter, "templates")
conf.Action.Before = append(conf.Action.Before, "echo \"zzz start\"")
conf.Action.After = append(conf.Action.After, "echo \"zzz end\"")
conf.Action.Exit = append(conf.Action.Exit, "echo \"exit\"")
conf.Link = "https://github.com/midoks/zzz"
d, err := yaml.Marshal(&conf)
if err != nil {
fmt.Println("create configuration file fail!")
return err
}
tools.WriteFile(file, string(d))
fmt.Println("create configuration file successfully!")
}
return nil
}