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