aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-03 18:13:49 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-03 18:13:49 -0500
commit38912d85394604fe9cc238ef6eb9f6e75ceb38f9 (patch)
tree861fc3af5d44ef8fbad738638f498c6e63bd1747
parentaff7b69cab2ac1d09b47f28c6fa653febd8595ea (diff)
downloadplanr-38912d85394604fe9cc238ef6eb9f6e75ceb38f9.tar.xz
planr-38912d85394604fe9cc238ef6eb9f6e75ceb38f9.zip
Add config command to retrieve configuration values and clean command to clean build files
-rw-r--r--cmd/planr/main.go51
-rw-r--r--cmd/planr/sub/build.go17
-rw-r--r--cmd/planr/sub/clean.go6
-rw-r--r--cmd/planr/sub/config.go28
-rw-r--r--cmd/planr/sub/evaluate.go4
-rw-r--r--runner.go24
6 files changed, 104 insertions, 26 deletions
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index 4b69a36..adcb50e 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -5,8 +5,11 @@ import (
"io"
"log"
"os"
+ "flag"
+ "golang.flu0r1ne.net/planr"
"golang.flu0r1ne.net/planr/cmd/planr/sub"
+ "golang.flu0r1ne.net/planr/adapters/gtest"
)
const (
@@ -20,7 +23,7 @@ func printUsage(w io.Writer) {
fmt.Fprintln(w, " build ")
fmt.Fprintln(w, " evaluate ")
fmt.Fprintln(w, " clean ")
-
+ fmt.Fprintln(w, " config ")
}
func dieUsage() {
@@ -28,6 +31,36 @@ func dieUsage() {
os.Exit(1)
}
+func NewRunner() planr.Runner {
+ r := planr.Runner {}
+
+ r.RegisterAdapter(&gtest.GtestAdapter{})
+
+ if wd, err := os.Getwd(); err == nil {
+ r.SetConfigDirFromTree(wd)
+ }
+
+ src := flag.String("srcdir", "", "source directory")
+ config := flag.String("configdir", "", "config directory")
+ build := flag.String("builddir", "", "build directory")
+
+ flag.Parse()
+
+ if src != nil && *src != "" {
+ r.SetSrcDir(*src)
+ }
+
+ if config != nil && *config != "" {
+ r.SetConfigDir(*config)
+ }
+
+ if build != nil && *build != "" {
+ r.SetBuildDir(*build)
+ }
+
+ return r
+}
+
func main() {
log.SetFlags(log.Llongfile | log.Lmsgprefix)
@@ -37,18 +70,22 @@ func main() {
dieUsage()
}
- subcommand := os.Args[1]
- subargs := os.Args[2:]
+ runner := NewRunner()
+
+ subcommand := flag.Arg(0)
+ subargs := flag.Args()[1:]
switch subcommand {
case "version":
fmt.Printf("%s\n", VERSION)
case "build":
- sub.Build(subargs)
- case "evaluate","eval":
- sub.Evaluate(subargs)
+ sub.Build(runner, subargs)
+ case "evaluate", "eval":
+ sub.Evaluate(runner, subargs)
case "clean":
- sub.Clean(subargs)
+ sub.Clean(runner, subargs)
+ case "config":
+ sub.Config(runner, subargs)
case "help", "-h", "-help", "--help":
printUsage(os.Stdout)
default:
diff --git a/cmd/planr/sub/build.go b/cmd/planr/sub/build.go
index 142ef1c..4a1cda9 100644
--- a/cmd/planr/sub/build.go
+++ b/cmd/planr/sub/build.go
@@ -2,22 +2,9 @@ package sub
import (
"golang.flu0r1ne.net/planr"
- "golang.flu0r1ne.net/planr/adapters/gtest"
- "os"
)
-func Runner() planr.Runner {
- r := planr.Runner {}
- r.RegisterAdapter(&gtest.GtestAdapter{})
-
- if wd, err := os.Getwd(); err == nil {
- r.SetConfigDirFromTree(wd)
- }
-
- return r
-}
-
-func Build(params []string) {
- Runner().Build()
+func Build(runner planr.Runner, params []string) {
+ runner.Build()
}
diff --git a/cmd/planr/sub/clean.go b/cmd/planr/sub/clean.go
index d40e967..d658c10 100644
--- a/cmd/planr/sub/clean.go
+++ b/cmd/planr/sub/clean.go
@@ -1,5 +1,7 @@
package sub
-func Clean(params []string) {
- Runner().Clean()
+import "golang.flu0r1ne.net/planr"
+
+func Clean(runner planr.Runner, params []string) {
+ runner.Clean()
}
diff --git a/cmd/planr/sub/config.go b/cmd/planr/sub/config.go
new file mode 100644
index 0000000..ee372c8
--- /dev/null
+++ b/cmd/planr/sub/config.go
@@ -0,0 +1,28 @@
+package sub
+
+import (
+ "golang.flu0r1ne.net/planr"
+ "fmt"
+ "os"
+)
+
+
+func Config(runner planr.Runner, params []string) {
+ if len(params) != 1 {
+ fmt.Fprintf(os.Stderr, "Usage: planr config <parameter>\n")
+ os.Exit(1)
+ }
+
+ key := params[0]
+
+ switch key {
+ case "builddir":
+ fmt.Printf("%s\n", runner.BuildDir())
+ case "configdir":
+ fmt.Printf("%s\n", runner.ConfigDir())
+ case "srcdir":
+ fmt.Printf("%s\n", runner.SrcDir())
+ default:
+ fmt.Fprintf(os.Stderr, "\"%s\" not found in configuration\n", key)
+ }
+}
diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go
index d183b86..79d377e 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -4,8 +4,8 @@ import (
"golang.flu0r1ne.net/planr"
)
-func Evaluate(params []string) {
- tcs := Runner().Evaluate()
+func Evaluate(runner planr.Runner, params []string) {
+ tcs := runner.Evaluate()
earned := 0.0
total := 0.0
diff --git a/runner.go b/runner.go
index 0a6243c..9014b8c 100644
--- a/runner.go
+++ b/runner.go
@@ -125,3 +125,27 @@ func (r Runner) Clean() {
func (r * Runner) SetConfigDirFromTree(childPath string) {
r.dirs.SetConfigFromTree(childPath)
}
+
+func (r * Runner) SetBuildDir(dir string) {
+ r.dirs.SetBuild(dir)
+}
+
+func (r * Runner) SetConfigDir(dir string) {
+ r.dirs.SetConfig(dir)
+}
+
+func (r * Runner) SetSrcDir(dir string) {
+ r.dirs.SetSrc(dir)
+}
+
+func (r Runner) BuildDir() string {
+ return r.dirs.Build();
+}
+
+func (r Runner) ConfigDir() string {
+ return r.dirs.Config()
+}
+
+func (r Runner) SrcDir() string {
+ return r.dirs.Src()
+}