-
Notifications
You must be signed in to change notification settings - Fork 47
/
config.go
40 lines (33 loc) · 980 Bytes
/
config.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
package dstask
import (
"os"
"path"
)
// Config models the dstask application's required configuration. All paths
// are absolute.
type Config struct {
// Path to the git repository
Repo string
// Path to the dstask local state file. State will differ between machines
StateFile string
// Path to the ids file
IDsFile string
// An unparsed context string, provided via DSTASK_CONTEXT
CtxFromEnvVar string
}
// NewConfig generates a new Config struct from the environment.
func NewConfig() Config {
var conf Config
conf.CtxFromEnvVar = getEnv("DSTASK_CONTEXT", "")
conf.Repo = getEnv("DSTASK_GIT_REPO", os.ExpandEnv("$HOME/.dstask"))
conf.StateFile = path.Join(conf.Repo, ".git", "dstask", "state.bin")
conf.IDsFile = path.Join(conf.Repo, ".git", "dstask", "ids.bin")
return conf
}
// getEnv returns an env var's value, or a default.
func getEnv(key string, _default string) string {
if val := os.Getenv(key); val != "" {
return val
}
return _default
}