package planr import ( "github.com/BurntSushi/toml" "log" "path" "strings" ) type Config struct { Version string } const PLANR_CONFIG_FILE = "config.toml" // TODO: REMOVE const STRICTLY_REQUIRE_CONFIG = false func DecodeConfig(configDir string) *Config { cfg := new(Config) configFile := path.Join(configDir, PLANR_CONFIG_FILE) if _, err := toml.DecodeFile(configFile, cfg); err != nil { cfg = nil // TODO: handle missing config if STRICTLY_REQUIRE_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] }