summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/config.go b/config.go
index d2d32e9..88495e3 100644
--- a/config.go
+++ b/config.go
@@ -4,19 +4,19 @@ import (
"github.com/BurntSushi/toml"
"log"
"path"
+ "strings"
)
-type planrConfig struct {
- Version string
- Project_title string
+type Config struct {
+ Version string
}
-const PLANR_CONFIG = "config.toml"
+const PLANR_CONFIG_FILE = "config.toml"
-func decodeConfig(configDir string) planrConfig {
- cfg := planrConfig { }
+func DecodeConfig(configDir string) Config {
+ cfg := Config { }
- configFile := path.Join(configDir, PLANR_CONFIG)
+ configFile := path.Join(configDir, PLANR_CONFIG_FILE)
if _, err := toml.DecodeFile(configFile, &cfg); err != nil {
// TODO: handle missing config
@@ -26,6 +26,19 @@ func decodeConfig(configDir string) planrConfig {
return cfg
}
-func (cfg planrConfig) isIncompatibleWithVersion() bool {
- return cfg.Version > VERSION
+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]
}