From 12e6824b8f0e6f6bb1ea921aa26a2d485fc9dcd9 Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 22 Mar 2018 16:26:17 +0000 Subject: Add -v flag --- weather.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/weather.go b/weather.go index d55297b..f14ec38 100644 --- a/weather.go +++ b/weather.go @@ -4,7 +4,6 @@ package main // TODO: decode weather type number // TODO: split out met office specific stuff to separate module // TODO: add other weather providers -// TODO: add -v verbose flag to show all data import ( "encoding/json" @@ -58,7 +57,10 @@ type WeatherParams struct { WT int // Weather Type } -var numdays = flag.Int("n", 2, "number of days to show") +var ( + numdays = flag.Int("n", 2, "number of days to show") + verbose = flag.Bool("v", false, "verbose: show all weather details") +) func main() { var r Response @@ -102,4 +104,7 @@ func main() { func prettyWeather(t string, w WeatherParams) { fmt.Printf("%s Type: %2d, Temp: %4.1f°C, Rain: %2d%%, Wind: %2.1fm/s\n", t, w.WT, w.T, w.PP, w.WS) + if *verbose { + fmt.Printf(" %+v\n", w) + } } -- cgit v1.2.3