summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 02:41:21 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 02:41:21 -0500
commita6f45bfa932b9e8e2393b5643e2bc38e44ba76df (patch)
treeb823cbca417ea4753f6dfe87ba986d2023ecb39a /config.go
parent4a6efc74aebcc689a734d05bc8435eb9560340e1 (diff)
downloaddeb-planr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.tar.xz
deb-planr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.zip
Add config w/ version information
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]
}