-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
53 lines (43 loc) · 1001 Bytes
/
init.go
File metadata and controls
53 lines (43 loc) · 1001 Bytes
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
// Copyright (C) 2018. See AUTHORS.
package rothko
import (
"fmt"
"io/ioutil"
"os"
"github.com/urfave/cli"
"github.com/vivint/rothko/config"
"github.com/zeebo/errs"
)
const configPath = "rothko.toml"
var initCommand = cli.Command{
Name: "init",
Usage: "create a new configuration",
ArgsUsage: t(`
`),
Description: t(`
The init command will create a new file named %q. It is meant to be
edited, but contains useful defaults.
`, configPath),
Action: func(c *cli.Context) error {
if err := checkArgs(c, 0); err != nil {
return err
}
_, err := os.Stat(configPath)
switch {
case os.IsNotExist(err):
case err == nil:
fmt.Printf("config file already exists. remove %q first\n",
configPath)
return handled.New("")
case err != nil:
return errs.Wrap(err)
}
err = ioutil.WriteFile(
configPath, []byte(config.InitialConfig), 0644)
if err != nil {
return errs.Wrap(err)
}
fmt.Printf("wrote initial config to %q\n", configPath)
return nil
},
}