package cmd import ( "fmt" "time" "git.sr.ht/~timharek/yr/cmd/internal/ui/table" "github.com/spf13/cobra" ) var todayCmd = &cobra.Command{ Use: "today ", Short: "Today's forecasted weather", Args: cobra.MaximumNArgs(1), Run: today, } func init() { rootCmd.AddCommand(todayCmd) } func today(cmd *cobra.Command, args []string) { f := forecastHelper(args) if isWeb { openBrowser("https://www.yr.no/en/forecast/hourly-table/%.4f,%.4f?i=0", f) } if isJson { outputJson(f.Forecast) } t := table.New("time", "temp.", "rain", "wind") today := time.Now() for _, item := range f.Forecast { if item.Time.Format(time.DateOnly) != today.Format(time.DateOnly) { continue } if !isUTC { item.Time = item.Time.Local() } t.Row( item.Time.Format("15:04"), fmt.Sprintf("%.1f °C", item.Temperature), fmt.Sprintf("%.1f mm", item.Percipitation), fmt.Sprintf("%.1f m/s %s", item.Wind.Speed, item.Wind.DirectionToString()), ) } fmt.Println(t) }