diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-05 02:41:21 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-05 02:41:21 -0500 |
commit | a6f45bfa932b9e8e2393b5643e2bc38e44ba76df (patch) | |
tree | b823cbca417ea4753f6dfe87ba986d2023ecb39a /config.go | |
parent | 4a6efc74aebcc689a734d05bc8435eb9560340e1 (diff) | |
download | deb-planr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.tar.xz deb-planr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.zip |
Add config w/ version information
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -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] } |