aboutsummaryrefslogtreecommitdiff
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
parent4a6efc74aebcc689a734d05bc8435eb9560340e1 (diff)
downloadplanr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.tar.xz
planr-a6f45bfa932b9e8e2393b5643e2bc38e44ba76df.zip
Add config w/ version information
-rw-r--r--cmd/planr/main.go6
-rw-r--r--cmd/planr/sub/build.go4
-rw-r--r--cmd/planr/sub/common.go15
-rw-r--r--cmd/planr/sub/evaluate.go4
-rw-r--r--config.go31
-rw-r--r--fs.go4
-rw-r--r--rubric_config.go4
7 files changed, 50 insertions, 18 deletions
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index d7f62aa..ce20811 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -79,6 +79,8 @@ func main() {
runner := getConfiguredRunner()
+ cfg := planr.DecodeConfig(runner.ConfigDir())
+
subcommand := flag.Arg(0)
subargs := flag.Args()[1:]
@@ -86,9 +88,9 @@ func main() {
case "version":
fmt.Printf("%s\n", planr.VERSION)
case "build":
- sub.Build(runner, subargs)
+ sub.Build(runner, subargs, cfg)
case "evaluate", "eval":
- sub.Evaluate(runner, subargs)
+ sub.Evaluate(runner, subargs, cfg)
case "clean":
sub.Clean(runner, subargs)
case "config":
diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go
index d24bb02..48edd9c 100644
--- a/cmd/planr/sub/build.go
+++ b/cmd/planr/sub/build.go
@@ -4,8 +4,8 @@ import (
"golang.flu0r1ne.net/planr"
)
-
-func Build(runner planr.Runner, params []string) {
+func Build(runner planr.Runner, params []string, cfg planr.Config) {
+ dieIncompatibleVersion(cfg)
tcs := runner.CollectCases()
runner.Build(tcs)
}
diff --git a/cmd/planr/sub/common.go b/cmd/planr/sub/common.go
new file mode 100644
index 0000000..67d07f8
--- /dev/null
+++ b/cmd/planr/sub/common.go
@@ -0,0 +1,15 @@
+package sub
+
+import (
+ "golang.flu0r1ne.net/planr"
+ "os"
+ "fmt"
+)
+
+func dieIncompatibleVersion(cfg planr.Config) {
+ if cfg.IncompatibleWithVersion() {
+ fmt.Fprintf(os.Stderr, "This version of PlanR (%v) is incompatible with config version %s\n", planr.VERSION, cfg.Version)
+ fmt.Fprintf(os.Stderr, "Please upgrade to version %s or greater\n", cfg.Version)
+ os.Exit(1)
+ }
+}
diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go
index 18cccb1..c2549be 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -4,7 +4,9 @@ import (
"golang.flu0r1ne.net/planr"
)
-func Evaluate(runner planr.Runner, params []string) {
+func Evaluate(runner planr.Runner, params []string, cfg planr.Config) {
+ dieIncompatibleVersion(cfg)
+
tcs := runner.CollectCases()
trs := runner.Evaluate(tcs)
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]
}
diff --git a/fs.go b/fs.go
index a42ff2c..04a3522 100644
--- a/fs.go
+++ b/fs.go
@@ -99,7 +99,7 @@ func collectFromDir(
// Process defaults for this directory if a defaults.toml is found
defaultsPath := path.Join(dir, DEFAULTS)
if info, err := os.Stat(defaultsPath); err == nil && !info.IsDir() {
- d, err := DecodeDefaults(defaultsPath, cfgs)
+ d, err := DecodeRubricDefaults(defaultsPath, cfgs)
if err != nil {
log.Fatalf("Error encounter in %s: %v\n", defaultsPath, err);
@@ -135,7 +135,7 @@ func collectFromDir(
}
// Decode a unit
- config, err := DecodeConfig(child, cfgs)
+ config, err := DecodeRubricConfig(child, cfgs)
if err != nil {
log.Fatalf("Error encountered in %s: %v", child, config)
diff --git a/rubric_config.go b/rubric_config.go
index 887bbb0..322e58a 100644
--- a/rubric_config.go
+++ b/rubric_config.go
@@ -135,7 +135,7 @@ func (defaults *Defaults) decodeAdapters(
}
// Decode defaults.toml
-func DecodeDefaults(path string, adapterCfg []AdapterConfig) (Defaults, error) {
+func DecodeRubricDefaults(path string, adapterCfg []AdapterConfig) (Defaults, error) {
defaults := Defaults { }
if _, err := toml.DecodeFile(path, &defaults); err != nil {
@@ -151,7 +151,7 @@ func DecodeDefaults(path string, adapterCfg []AdapterConfig) (Defaults, error) {
}
// Decode an individual unit
-func DecodeConfig(path string, adapterCfg []AdapterConfig) (TestCaseConfig, error) {
+func DecodeRubricConfig(path string, adapterCfg []AdapterConfig) (TestCaseConfig, error) {
config := TestCaseConfig { }
if _, err := toml.DecodeFile(path, &config); err != nil {