From a6f45bfa932b9e8e2393b5643e2bc38e44ba76df Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Sun, 5 Sep 2021 02:41:21 -0500 Subject: Add config w/ version information --- config.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'config.go') 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] } -- cgit v1.2.3