From 71ffa9389fcb1a6dadc6cb060aadc0bbfbae95c2 Mon Sep 17 00:00:00 2001 From: Rob King Date: Wed, 17 Oct 2018 18:43:06 -0400 Subject: [PATCH] Add a flag to only show failing jobs with the status command --- cmd/riffraff/main.go | 7 ++++--- internal/commands/status.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/riffraff/main.go b/cmd/riffraff/main.go index b4690ad..835efd8 100644 --- a/cmd/riffraff/main.go +++ b/cmd/riffraff/main.go @@ -11,8 +11,9 @@ import ( ) var ( - statusCommand = kingpin.Command("status", "Show the status of all matching jobs") - statusRegexArg = statusCommand.Arg("regex", "The regular expression to match for the job names").Default(".*").String() + statusCommand = kingpin.Command("status", "Show the status of all matching jobs") + statusRegexArg = statusCommand.Arg("regex", "The regular expression to match for the job names").Default(".*").String() + statusOnlyFailingArg = statusCommand.Flag("only-failing", "Show only failing jobs").Bool() buildCommand = kingpin.Command("build", "Trigger build for all matching jobs") buildRegexArg = buildCommand.Arg("regex", "The regular expression to match for the job names").Default(".*").String() @@ -65,7 +66,7 @@ func main() { // e.g. https://github.com/mitchellh/cli switch kingpin.Parse() { case "status": - err = commands.NewStatus(jenkins, *statusRegexArg).Exec() + err = commands.NewStatus(jenkins, *statusRegexArg, *statusOnlyFailingArg).Exec() case "diff": err = commands.NewDiff(jenkins, *diffJobArg, *diffBuild1Arg, *diffBuild2Arg).Exec() case "build": diff --git a/internal/commands/status.go b/internal/commands/status.go index c508171..a918fca 100644 --- a/internal/commands/status.go +++ b/internal/commands/status.go @@ -23,12 +23,13 @@ var ( ) type Status struct { - jenkins *gojenkins.Jenkins - regex string + jenkins *gojenkins.Jenkins + regex string + onlyFailing bool } -func NewStatus(jenkins *gojenkins.Jenkins, regex string) *Status { - return &Status{jenkins, regex} +func NewStatus(jenkins *gojenkins.Jenkins, regex string, onlyFailing bool) *Status { + return &Status{jenkins, regex, onlyFailing} } func (s Status) Exec() error { @@ -70,6 +71,10 @@ func (s Status) print(job gojenkins.InnerJob) error { } } + if s.onlyFailing && marker != Bad { + return nil + } + fmt.Printf("%v %v (%v)\n", marker, job.Name, job.Url) return nil }