From 6cb3994ae9af6720a94be3dd30b5f98d959ed70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20H=C3=A5rek=20Andreassen?= Date: Wed, 2 Oct 2024 20:40:49 +0200 Subject: [PATCH] feat: Add interval to forecast cmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim HĂ„rek Andreassen --- cmd/flags/flags.go | 7 ++++--- cmd/forecast.go | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/flags/flags.go b/cmd/flags/flags.go index 2a627fb..c5fa181 100644 --- a/cmd/flags/flags.go +++ b/cmd/flags/flags.go @@ -1,7 +1,8 @@ package flags const ( - LON = "lon" - LAT = "lat" - JSON = "json" + LON = "lon" + LAT = "lat" + JSON = "json" + INTERVAL = "interval" ) diff --git a/cmd/forecast.go b/cmd/forecast.go index 57d57bf..61bacd6 100644 --- a/cmd/forecast.go +++ b/cmd/forecast.go @@ -24,6 +24,7 @@ var forecastCmd = &cobra.Command{ func init() { rootCmd.AddCommand(forecastCmd) + rootCmd.PersistentFlags().IntP(flags.INTERVAL, "i", 0, "Number of hours to output") } func forecast(cmd *cobra.Command, args []string) { @@ -31,6 +32,7 @@ func forecast(cmd *cobra.Command, args []string) { cobra.CheckErr(err) lon, _ := cmd.Flags().GetFloat64(flags.LON) lat, _ := cmd.Flags().GetFloat64(flags.LAT) + interval, _ := cmd.Flags().GetInt(flags.INTERVAL) c, err := yr.New() cobra.CheckErr(err) @@ -43,12 +45,14 @@ func forecast(cmd *cobra.Command, args []string) { if len(args) == 0 { f, err = c.ForecastCoords(&nominatim.Coordinates{Longitude: lon, Latitude: lat}, nil) cobra.CheckErr(err) - } else { location := args[0] f, err = c.Forecast(location) cobra.CheckErr(err) + } + if interval > 0 { + f = f[:interval] } if isJson {