forked from mbellotti/netback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (37 loc) · 961 Bytes
/
main.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 (
"fmt"
"os"
"github.com/mbellotti/netback/cmd"
"github.com/mitchellh/go-homedir"
_ "github.com/spf13/cobra"
"github.com/spf13/viper"
)
func main() {
h, err := homedir.Dir()
configpath := fmt.Sprintf("%s/netback", h)
if _, err := os.Stat(configpath); os.IsNotExist(err) {
err := os.Mkdir(configpath, 0755)
if err != nil {
fmt.Println(err)
}
}
filepath := fmt.Sprintf("%s/config.yaml", configpath)
if _, err := os.Stat(filepath); os.IsNotExist(err) {
_, err = os.Create(filepath)
if err != nil {
fmt.Println(err)
}
}
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml")
viper.AddConfigPath(configpath) // path to look for the config file in
fmt.Println(viper.ConfigFileUsed())
err = viper.ReadInConfig()
if err != nil {
fmt.Println("Configuration not found, please run `netback config` to set up")
} else {
viper.WatchConfig()
}
cmd.Execute()
}