Skip to content

Commit

Permalink
Add flags to the CLI to allow filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
daenney committed Dec 5, 2020
1 parent 15a55a2 commit 6cfb38a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"log"
"os"
Expand All @@ -12,11 +13,35 @@ import (
)

func main() {

host := flag.String("host", "", "show events matching this host")
runner := flag.String("runner", "", "show events matching this runner")
title := flag.String("title", "", "show events matching this title")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprint(flag.CommandLine.Output(), "\n")
fmt.Fprint(flag.CommandLine.Output(), "When using filters, each filter is applied and the resulting filtered schedule is then filtered with the next filter. This means filters are additive, so you can't say show me events for this host or this runner.\n")
}

flag.Parse()

schedule, err := gdq.GetSchedule(gdq.AGDQ2021, nil)
if err != nil {
log.Fatalln(err)
}

if *host != "" {
schedule = schedule.ForHost(*host)
}
if *runner != "" {
schedule = schedule.ForRunner(*runner)
}
if *title != "" {
schedule = schedule.ForTitle(*title)
}

if schedule != nil && len(schedule.Events) > 0 {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)
fmt.Fprintln(w, "Start Time\tTitle\tEstimate\tRunners\tHosts")
Expand Down

0 comments on commit 6cfb38a

Please sign in to comment.