// $TheSupernovaDuo: yuuka,v 0.1.1 2023/5/29 18:19:14 yakumo_izuru Exp $ package main import ( "fmt" "io" "log" "net/http" "github.com/integrii/flaggy" ) var ( format string = "AT" region string ) func main() { flaggy.SetDescription("Yuuka is a wttr.in client") flaggy.SetVersion(FullVersion()) forecastCmd := flaggy.NewSubcommand("forecast") forecastCmd.String(&format, "f", "format", "View options") forecastCmd.String(®ion, "r", "region", "Where to look at") forecastCmd.Description = "Check the forecast for a specified location" flaggy.AttachSubcommand(forecastCmd, 1) moonCmd := flaggy.NewSubcommand("moon") moonCmd.String(&format, "f", "format", "View options") moonCmd.Description = "Check the Moon's phases" flaggy.AttachSubcommand(moonCmd, 1) flaggy.ShowHelpOnUnexpectedDisable() flaggy.Parse() if forecastCmd.Used { ShowForecast(region, format) } else if moonCmd.Used { ShowMoonPhases(format) } else { flaggy.ShowHelpAndExit("A subcommand is required") } } func ShowForecast(region string, format string) { query := "https://wttr.in/" + region + "?" + format resp, err := http.Get(query) sanityCheck(err) defer resp.Body.Close() body, err := io.ReadAll(resp.Body) sanityCheck(err) fmt.Printf("%s", body) } func ShowMoonPhases(format string) { query := "https://wttr.in/" + "moon" + "?" + format resp, err := http.Get(query) sanityCheck(err) defer resp.Body.Close() body, err := io.ReadAll(resp.Body) sanityCheck(err) fmt.Printf("%s\n", body) } func sanityCheck(err error) { if err != nil { log.Fatal(err) } }