-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_init.go
42 lines (35 loc) · 845 Bytes
/
cmd_init.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
package main
import (
"encoding/json"
"os"
"github.com/fatih/color"
)
// CLI Command
type InitCmd struct {
}
// Command Handler
func (r *InitCmd) Run(ctx *Globals) error {
color.Green("Initializing ADR configuration at " + configFolderPath)
initConfig(configFolderPath)
initTemplate()
return nil
}
func initConfig(baseDir string) {
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
os.Mkdir(baseDir, 0744)
} else {
color.Red("Directory" + baseDir + " already exists. Not overriding.")
os.Exit(-1)
}
config := AdrConfig{baseDir, 0}
bytes, err := json.MarshalIndent(config, "", " ")
if err != nil {
panic(err)
}
color.White("Writing new configuration at: " + configFilePath)
os.WriteFile(configFilePath, bytes, 0644)
}
func initTemplate() {
body := []byte(TEMPLATE1)
os.WriteFile(templateFilePath, body, 0644)
}