Skip to content

Commit

Permalink
Add quiet output
Browse files Browse the repository at this point in the history
  • Loading branch information
msharris committed Mar 15, 2024
1 parent ecfbb27 commit 3d3df71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Options struct {
Locations []string
Sort Field
Reverse bool
Quiet bool
}

type Field string
Expand Down Expand Up @@ -89,7 +90,7 @@ func Run(options Options) error {
slices.Reverse(stations)
}

show(stations)
show(stations, options.Quiet)

return nil
}
Expand Down Expand Up @@ -146,15 +147,21 @@ func sort(stations []Station, f Field) {
}
}

func show(stations []Station) {
func show(stations []Station, quiet bool) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t", "Id", "Location", "Index", "Time", "Status"))
for _, s := range stations {
status := "-"
if !s.Available {
status = "n/a"
if quiet {
for _, s := range stations {
fmt.Fprintln(w, fmt.Sprintf("%v\t%.1f\t", s.Name, s.UVIndex))
}
} else {
fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t", "Id", "Location", "Index", "Time", "Status"))
for _, s := range stations {
status := "-"
if !s.Available {
status = "n/a"
}
fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%.1f\t%v\t%v\t", s.Id, s.Name, s.UVIndex, s.Time.Format("15:04"), status))
}
fmt.Fprintln(w, fmt.Sprintf("%v\t%v\t%.1f\t%v\t%v\t", s.Id, s.Name, s.UVIndex, s.Time.Format("15:04"), status))
}
w.Flush()
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func init() {
rootCmd.Flags().StringSliceVarP(&flags.Locations, "locations", "l", nil, "comma-separated list of locations to display (accepts id and name)")
rootCmd.Flags().VarP(&flags.Sort, "sort", "s", "field to sort observations by")
rootCmd.Flags().BoolVarP(&flags.Reverse, "reverse", "r", false, "print observations in reverse order")
rootCmd.Flags().BoolVarP(&flags.Quiet, "quiet", "q", false, "reduce the output")
}

0 comments on commit 3d3df71

Please sign in to comment.