blob: 88495e356d94a5adc85c307460d59c269f701e92 (
plain)
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
|
package planr
import (
"github.com/BurntSushi/toml"
"log"
"path"
"strings"
)
type Config struct {
Version string
}
const PLANR_CONFIG_FILE = "config.toml"
func DecodeConfig(configDir string) Config {
cfg := Config { }
configFile := path.Join(configDir, PLANR_CONFIG_FILE)
if _, err := toml.DecodeFile(configFile, &cfg); err != nil {
// TODO: handle missing config
log.Fatalf("Could not decode global configuration %s: %v", configFile, err)
}
return cfg
}
func (cfg Config) IncompatibleWithVersion() bool {
if strings.Count(cfg.Version, ".") != 2 {
log.Fatalf("Version %s is not semantic", cfg.Version)
}
cfgbits := strings.SplitN(cfg.Version, ".", 2)
bits := strings.SplitN(VERSION, ".", 2)
// major version change
if cfgbits[0] != bits[0] {
return true
}
// Config newer, possible feature additions
return cfgbits[1] > bits[1]
}
|