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 --- cmd/planr/main.go | 6 ++++-- cmd/planr/sub/build.go | 4 ++-- cmd/planr/sub/common.go | 15 +++++++++++++++ cmd/planr/sub/evaluate.go | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 cmd/planr/sub/common.go (limited to 'cmd') 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) -- cgit v1.2.3