aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-19 00:27:55 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-19 00:27:55 -0500
commit1d479733bcbeb630557cd07f721d4510e989934c (patch)
tree42422bd0c2ecc51869eceb8bbead8f5c3e58855f /cmd
parent86d8789f065636779d3cecded363743b2a39bb47 (diff)
downloadplanr-1d479733bcbeb630557cd07f721d4510e989934c.tar.xz
planr-1d479733bcbeb630557cd07f721d4510e989934c.zip
Add list command, copy for bash command, and ability to run non-directory commands anywhereHEADv0.1.6master
Diffstat (limited to 'cmd')
-rw-r--r--cmd/planr/main.go30
-rw-r--r--cmd/planr/sub/cli.go14
-rw-r--r--cmd/planr/sub/evaluate.go28
-rw-r--r--cmd/planr/sub/list.go13
4 files changed, 68 insertions, 17 deletions
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index 2243203..e2ed19f 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -80,29 +80,37 @@ func main() {
dieUsage()
}
+ subcommand := flag.Arg(0)
+ subargs := flag.Args()[1:]
+
+ switch subcommand {
+ case "version":
+ fmt.Printf("%s\n", planr.VERSION)
+ os.Exit(0)
+ case "help", "-h", "-help", "--help":
+ printUsage(os.Stdout)
+ os.Exit(0)
+ case "build", "evaluate", "eval", "clean", "config", "list":
+ break
+ default:
+ fmt.Fprintf(os.Stderr, "unrecognized command %s\n", subcommand)
+ dieUsage()
+ }
+
runner := getConfiguredRunner()
cfg := planr.DecodeConfig(runner.ConfigDir())
- subcommand := flag.Arg(0)
- subargs := flag.Args()[1:]
-
switch subcommand {
- case "version":
- fmt.Printf("%s\n", planr.VERSION)
case "build":
sub.Build(runner, subargs, cfg)
case "evaluate", "eval":
sub.Evaluate(runner, subargs, cfg)
+ case "list":
+ sub.List(runner, subargs, cfg)
case "clean":
sub.Clean(runner, subargs)
case "config":
sub.Config(runner, subargs)
- case "help", "-h", "-help", "--help":
- printUsage(os.Stdout)
- default:
- fmt.Fprintf(os.Stderr, "unrecognized command %s\n", subcommand)
- dieUsage()
}
-
}
diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go
index 5defa96..9e1099c 100644
--- a/cmd/planr/sub/cli.go
+++ b/cmd/planr/sub/cli.go
@@ -82,6 +82,20 @@ func (opt PrintOpts) HasFlag(flag PrintOpts) bool {
return (opt & flag) == flag
}
+func tcPrint(tc planr.TestCase) {
+ title := ""
+
+ if tc.Config.Title != "" {
+ title = tc.Config.Title
+ } else {
+ title = tc.Cname
+ }
+
+ col_title.Println(title)
+ pprintLabeled("id", tc.Cname)
+ fmt.Println()
+}
+
func tcPprint(tr planr.TestResult, opt PrintOpts) {
tcStatusLine(tr)
diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go
index 4f5e4e1..3f1718f 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -2,9 +2,10 @@ package sub
import (
"encoding/json"
+ "flag"
"fmt"
+ "io/ioutil"
"log"
- "flag"
"golang.flu0r1ne.net/planr"
)
@@ -30,26 +31,39 @@ func prettyPrint(results gradingResults, verbose, summarize bool) {
}
}
-func jsonPrint(results gradingResults) {
+func jsonPrint(results gradingResults, file string) {
res, err := json.Marshal(results)
if err != nil {
log.Fatalf("Error printing JSON: %v\n", err)
}
- fmt.Println(string(res))
+ if file == "" {
+ fmt.Println(string(res))
+ return
+ }
+
+
+ if err := ioutil.WriteFile(file, res, 0664); err != nil {
+ log.Fatalf("Could not write JSON file %v", err)
+ }
}
func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) {
f := flag.NewFlagSet("evaluate", flag.ExitOnError)
jsonOutput := f.Bool("json", false, "print json output")
+ jsonFile := f.String("json_to_file", "", "export json to a file")
extra := f.Bool("extra", false, "print extra grading information")
dieIncompatibleVersion(cfg)
f.Parse(params)
+ if *jsonFile != "" && *jsonOutput {
+ log.Fatalf("-json and -json_to_file are mutually exclusive")
+ }
+
tcs := runner.CollectCases()
// Filter those tests which patch IDs in params
@@ -80,9 +94,11 @@ func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) {
Score: planr.Score(trs),
}
- if *jsonOutput {
- jsonPrint(results)
- } else {
+ if *jsonOutput || *jsonFile != "" {
+ jsonPrint(results, *jsonFile)
+ }
+
+ if ! *jsonOutput {
prettyPrint(results, *extra, summarizeScore)
}
}
diff --git a/cmd/planr/sub/list.go b/cmd/planr/sub/list.go
new file mode 100644
index 0000000..911a7e6
--- /dev/null
+++ b/cmd/planr/sub/list.go
@@ -0,0 +1,13 @@
+package sub
+
+import (
+ "golang.flu0r1ne.net/planr"
+)
+
+func List(runner planr.Runner, params []string, cfg * planr.Config) {
+ tcs := runner.CollectCases()
+
+ for _, tc := range tcs {
+ tcPrint(tc)
+ }
+}