File tree 2 files changed +34
-9
lines changed
2 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,15 @@ package cmd
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "log"
7
+ "os"
8
+ "path"
9
+
10
+ "github.com/msp301/zb/config"
6
11
"github.com/msp301/zb/editor"
7
12
"github.com/msp301/zb/graph"
8
13
"github.com/spf13/cobra"
9
14
"github.com/spf13/viper"
10
- "log"
11
- "os"
12
- "path"
13
15
)
14
16
15
17
var cfgFile string
@@ -51,14 +53,11 @@ func initConfig() {
51
53
if cfgFile != "" {
52
54
viper .SetConfigFile (cfgFile )
53
55
} else {
54
- home , err := os .UserHomeDir ()
55
- cobra .CheckErr (err )
56
-
57
56
viper .AddConfigPath ("." )
58
- viper .AddConfigPath (home )
57
+ viper .AddConfigPath (config . GlobalConfigDir )
59
58
60
- viper .SetConfigType ("toml" )
61
- viper .SetConfigName (".zb" )
59
+ viper .SetConfigType (config . CONFIG_TYPE )
60
+ viper .SetConfigName (config . CONFIG_NAME )
62
61
}
63
62
64
63
if err := viper .ReadInConfig (); err != nil {
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+ "path/filepath"
6
+ "strings"
7
+ )
8
+
9
+ const CONFIG_NAME = ".zb"
10
+ const CONFIG_TYPE = "toml"
11
+
12
+ var ConfigFile string
13
+ var GlobalConfigDir string
14
+ var GlobalConfigFile string
15
+
16
+ func init () {
17
+ ConfigFile = strings .Join ([]string {CONFIG_NAME , CONFIG_TYPE }, "." )
18
+
19
+ GlobalConfigDir = ""
20
+ home , err := os .UserHomeDir ()
21
+ if err == nil {
22
+ GlobalConfigDir = home
23
+ }
24
+
25
+ GlobalConfigFile = filepath .Join (GlobalConfigDir , ConfigFile )
26
+ }
You can’t perform that action at this time.
0 commit comments