From cc9e3965a365a9b98fd4c454017dfa8e40860fb1 Mon Sep 17 00:00:00 2001 From: Flu0r1ne Date: Mon, 6 Sep 2021 21:06:02 -0500 Subject: Add --extra flag to print addtional configuration info --- cmd/planr/sub/cli.go | 28 +++++++++++++++++++++------- cmd/planr/sub/evaluate.go | 13 ++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'cmd') diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go index e6f2256..4d29144 100644 --- a/cmd/planr/sub/cli.go +++ b/cmd/planr/sub/cli.go @@ -17,8 +17,8 @@ var ( func tcTitle(tr planr.TestResult) string { title := tr.Tc.Cname - if tr.Tc.Config.Title != nil { - title = *tr.Tc.Config.Title + if tr.Tc.Config.Title != "" { + title = tr.Tc.Config.Title } return title @@ -70,20 +70,34 @@ func tcStatusLine(tr planr.TestResult) { col_title.Println(title); } -func tcPprint(tr planr.TestResult) { +type PrintOpts int + +const ( + PRINT_CONCISE PrintOpts = 1 << iota + PRINT_DESCRIPTION + PRINT_POINTS +) + +func (opt PrintOpts) HasFlag(flag PrintOpts) bool { + return (opt & flag) == flag +} + +func tcPprint(tr planr.TestResult, opt PrintOpts) { tcStatusLine(tr) tc := tr.Tc pprintLabeled("id", tc.Cname) - if tc.Config.Points != nil { + if tc.Config.Points != nil && opt.HasFlag(PRINT_POINTS) { points := fmt.Sprintf("%.1f", *tc.Config.Points) - pprintLabeled("points", points) + pprintLabeled("points1", points) } - if tc.Config.Description != nil { - pprintLabeled("description", *tc.Config.Description) + if tc.Config.Description != "" && opt.HasFlag(PRINT_DESCRIPTION) { + tabbed := strings.ReplaceAll(tc.Config.Description, "\n", "\n ") + + pprintLabeled("description", tabbed) } if tr.Status == planr.COMPILATION_FAILURE { diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go index 30d30d2..4f5e4e1 100644 --- a/cmd/planr/sub/evaluate.go +++ b/cmd/planr/sub/evaluate.go @@ -14,9 +14,15 @@ type gradingResults struct { Score planr.Scoring } -func prettyPrint(results gradingResults, summarize bool) { +func prettyPrint(results gradingResults, verbose, summarize bool) { for _, tr := range results.TestResults { - tcPprint(tr) + opts := PRINT_CONCISE + + if verbose { + opts = opts | PRINT_DESCRIPTION | PRINT_POINTS + } + + tcPprint(tr, opts) } if summarize { @@ -38,6 +44,7 @@ func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { f := flag.NewFlagSet("evaluate", flag.ExitOnError) jsonOutput := f.Bool("json", false, "print json output") + extra := f.Bool("extra", false, "print extra grading information") dieIncompatibleVersion(cfg) @@ -76,6 +83,6 @@ func Evaluate(runner planr.Runner, params []string, cfg *planr.Config) { if *jsonOutput { jsonPrint(results) } else { - prettyPrint(results, summarizeScore) + prettyPrint(results, *extra, summarizeScore) } } -- cgit v1.2.3