diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/planr/main.go | 51 | ||||
-rw-r--r-- | cmd/planr/sub/build.go | 17 | ||||
-rw-r--r-- | cmd/planr/sub/clean.go | 6 | ||||
-rw-r--r-- | cmd/planr/sub/config.go | 28 | ||||
-rw-r--r-- | cmd/planr/sub/evaluate.go | 4 |
5 files changed, 80 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(>est.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(>est.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 |