package cmd import ( "fmt" "io" "log" "net/http" "github.com/spf13/cobra" ) var forecastCmd = &cobra.Command{ Use: "forecast", Short: "Display the weather forecast for a specific location", Run: func(cmd *cobra.Command, args []string) { query := "https://wttr.in" + region + "?" + format resp, err := http.Get(query) if err != nil { log.Fatal(err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", body) }, } func init() { rootCmd.AddCommand(forecastCmd) }