-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
130 lines (109 loc) · 3.89 KB
/
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package initialize
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/ironstar-io/tokaido/conf"
"github.com/ironstar-io/tokaido/constants"
"github.com/ironstar-io/tokaido/system"
"github.com/ironstar-io/tokaido/system/fs"
"github.com/ironstar-io/tokaido/utils"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
"github.com/logrusorgru/aurora"
)
// TokConfig - loads the config from a file if specified, otherwise from the environment
func TokConfig(command string) {
conf.ValidProjectRoot()
createDotTok()
createGlobalDotTok()
viper.SetEnvPrefix("TOK")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
removeOldGlobalConfig()
readProjectConfig(command)
// readGlobalConfig()
}
func emojiDefaults() bool {
return true
}
// Tokaido 1.7 used ~/.tok/config.yml as the global config file, which confused users
// when talking to them about "config.yml". 1.8 changes this to ~/.tok/global.yml.
// removeOldGlobalConfig will remove the old config file and advise the user.
func removeOldGlobalConfig() {
h, err := homedir.Dir()
if err != nil {
log.Fatalln("Unable to resolve home directory so can't initialise Tokaido. Sorry!")
}
oc := filepath.Join(h, ".tok/config.yml")
if fs.CheckExists(oc) {
fs.Remove(oc)
fmt.Println(aurora.Magenta("Tokaido has removed your legacy global config file in $HOME/.tok/config.yml. You don't need it anymore"))
}
}
func readProjectConfig(command string) {
utils.DebugString("reading project config")
pr := fs.ProjectRoot()
switch system.CheckOS() {
case "osx":
viper.SetDefault("Global.Syncservice", "docker")
default:
viper.SetDefault("Global.Syncservice", "unison")
}
viper.SetDefault("Global.Syncsvc.Launchdpath", filepath.Join(fs.HomeDir(), "/Library/LaunchAgents/"))
viper.SetDefault("Global.Syncsvc.Systemdpath", filepath.Join(fs.HomeDir(), "/.config/systemd/user/"))
viper.SetDefault("Tokaido.Customcompose", viper.GetBool("customCompose"))
viper.SetDefault("Tokaido.Debug", viper.GetBool("debug"))
viper.SetDefault("Tokaido.Force", viper.GetBool("force"))
viper.SetDefault("Tokaido.Yes", viper.GetBool("yes"))
viper.SetDefault("Tokaido.Stability", constants.EdgeVersion)
viper.SetDefault("Tokaido.Dependencychecks", true)
viper.SetDefault("Tokaido.Enableemoji", emojiDefaults())
viper.SetDefault("Tokaido.Phpversion", "7.2")
viper.SetDefault("Tokaido.Xdebug", false)
viper.SetDefault("Tokaido.Project.Name", strings.Replace(filepath.Base(pr), ".", "", -1))
viper.SetDefault("Drupal.FilePublicPath", "")
viper.SetDefault("Drupal.FilePrivatePath", constants.DefaultDrupalPrivatePath)
viper.SetDefault("Drupal.FileTemporaryPath", constants.DefaultDrupalTemporaryPath)
viper.SetDefault("Global.Syncsvc.Enabled", true)
viper.SetDefault("Global.Proxy.Enabled", true)
if command == "new" {
viper.SetDefault("Services.Adminer.Enabled", true)
}
viper.SetDefault("Services.Memcache.Enabled", false)
viper.SetDefault("Services.Mailhog.Enabled", true)
viper.SetDefault("Services.Solr.Enabled", false)
viper.SetConfigType("yaml")
viper.SetConfigName("config")
viper.AddConfigPath(filepath.Join(pr, ".tok"))
viper.ReadInConfig()
// Check and error if trying to pass in invalid values
_, err := conf.PopulateConfig(new(conf.Config))
if err != nil {
log.Fatalln("Unable to load your configuration\n", err)
}
}
func createDotTok() {
d := filepath.Join(fs.ProjectRoot(), ".tok")
if fs.CheckExists(d) == false {
err := os.MkdirAll(d, os.ModePerm)
if err != nil {
fmt.Println("There was an error creating the config directory:", err)
}
}
}
func createGlobalDotTok() {
h, err := homedir.Dir()
if err != nil {
log.Fatalln("Unable to resolve home directory, unable to initialise. Sorry!")
}
d := filepath.Join(h, ".tok")
if fs.CheckExists(d) == false {
err := os.MkdirAll(d, os.ModePerm)
if err != nil {
fmt.Println("There was an error creating the global config directory:", err)
}
}
}