feat: Add interval to forecast cmd
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
65dd6ad1f5
commit
6cb3994ae9
2 changed files with 9 additions and 4 deletions
|
@ -1,7 +1,8 @@
|
||||||
package flags
|
package flags
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LON = "lon"
|
LON = "lon"
|
||||||
LAT = "lat"
|
LAT = "lat"
|
||||||
JSON = "json"
|
JSON = "json"
|
||||||
|
INTERVAL = "interval"
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,6 +24,7 @@ var forecastCmd = &cobra.Command{
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(forecastCmd)
|
rootCmd.AddCommand(forecastCmd)
|
||||||
|
rootCmd.PersistentFlags().IntP(flags.INTERVAL, "i", 0, "Number of hours to output")
|
||||||
}
|
}
|
||||||
|
|
||||||
func forecast(cmd *cobra.Command, args []string) {
|
func forecast(cmd *cobra.Command, args []string) {
|
||||||
|
@ -31,6 +32,7 @@ func forecast(cmd *cobra.Command, args []string) {
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
lon, _ := cmd.Flags().GetFloat64(flags.LON)
|
lon, _ := cmd.Flags().GetFloat64(flags.LON)
|
||||||
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
|
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
|
||||||
|
interval, _ := cmd.Flags().GetInt(flags.INTERVAL)
|
||||||
|
|
||||||
c, err := yr.New()
|
c, err := yr.New()
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
@ -43,12 +45,14 @@ func forecast(cmd *cobra.Command, args []string) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
f, err = c.ForecastCoords(&nominatim.Coordinates{Longitude: lon, Latitude: lat}, nil)
|
f, err = c.ForecastCoords(&nominatim.Coordinates{Longitude: lon, Latitude: lat}, nil)
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
location := args[0]
|
location := args[0]
|
||||||
f, err = c.Forecast(location)
|
f, err = c.Forecast(location)
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if interval > 0 {
|
||||||
|
f = f[:interval]
|
||||||
}
|
}
|
||||||
|
|
||||||
if isJson {
|
if isJson {
|
||||||
|
|
Loading…
Reference in a new issue