/
v0.go
85 lines (65 loc) · 1.49 KB
/
v0.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
package v0
import (
"github.com/metamatex/metamate/metamate/pkg/v0/config"
"github.com/metamatex/metamate/metamate/pkg/v0/types"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var fs afero.Fs
var gArgs = types.GlobalArgs{}
var version = types.Version{}
var v0Cmd = &cobra.Command{
Use: "v0",
Short: "",
Long: "",
}
func AddV0(cmd *cobra.Command, prefix bool, v types.Version) {
fs = afero.NewOsFs()
parentCmd := cmd
if prefix {
parentCmd.AddCommand(v0Cmd)
parentCmd = v0Cmd
}
version = v
addInit(parentCmd)
addServe(parentCmd)
addUpdate(parentCmd)
addVersion(parentCmd)
parentCmd.PersistentFlags().StringVarP(&gArgs.ConfigPath, "config", "c", config.ConfigFile, "config file")
parentCmd.PersistentFlags().CountVarP(&gArgs.VerbosityLevel, "verbose", "v", "")
}
func readProjectConfig(args types.GlobalArgs) (c types.Config, err error) {
v := viper.New()
if args.ConfigPath != config.ConfigFile {
v.SetConfigFile(args.ConfigPath)
} else {
v.AddConfigPath(".")
v.SetConfigName(config.ConfigFileName)
}
v.AutomaticEnv()
err = v.ReadInConfig()
if err != nil {
return
}
err = v.Unmarshal(&c)
if err != nil {
return
}
return
}
func hasConfig(args types.GlobalArgs) (bool) {
v := viper.New()
if args.ConfigPath != config.ConfigFile {
v.SetConfigFile(args.ConfigPath)
} else {
v.AddConfigPath(".")
v.SetConfigName(config.ConfigFileName)
}
v.AutomaticEnv()
err := v.ReadInConfig()
if err != nil {
return false
}
return true
}