Changeset 2 in code for trunk/main.go
- Timestamp:
- May 29, 2023, 10:44:48 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/main.go
r1 r2 1 // $TheSupernovaDuo: yuuka,v master 2023/5/29 17:54:15yakumo_izuru Exp $1 // $TheSupernovaDuo: yuuka,v 0.1.1 2023/5/29 18:19:14 yakumo_izuru Exp $ 2 2 package main 3 3 … … 7 7 "log" 8 8 "net/http" 9 "os" 9 10 "github.com/integrii/flaggy" 10 11 ) 11 12 var ( 12 format = "?AT"13 url = "https://wttr.in"13 format string = "AT" 14 region string 14 15 ) 15 16 func main() { 16 if len(os.Args) == 1 { 17 PrintUsage() 18 } 17 flaggy.SetDescription("Yuuka is a wttr.in client") 18 flaggy.SetVersion(FullVersion()) 19 20 forecastCmd := flaggy.NewSubcommand("forecast") 21 forecastCmd.String(&format, "f", "format", "View options") 22 forecastCmd.String(®ion, "r", "region", "Where to look at") 23 forecastCmd.Description = "Check the forecast for a specified location" 19 24 20 cmd := os.Args[1]25 flaggy.AttachSubcommand(forecastCmd, 1) 21 26 22 switch cmd { 23 case "forecast": 24 ShowForecast() 25 case "moon": 26 ShowMoonPhases() 27 moonCmd := flaggy.NewSubcommand("moon") 28 moonCmd.String(&format, "f", "format", "View options") 29 moonCmd.Description = "Check the Moon's phases" 30 31 flaggy.AttachSubcommand(moonCmd, 1) 32 33 flaggy.ShowHelpOnUnexpectedDisable() 34 flaggy.Parse() 35 36 if forecastCmd.Used { 37 ShowForecast(region, format) 38 } else if moonCmd.Used { 39 ShowMoonPhases(format) 40 } else { 41 flaggy.ShowHelpAndExit("A subcommand is required") 27 42 } 28 43 } 29 func PrintUsage() { 30 fmt.Println("Yuuka is a wttr.in client") 31 fmt.Printf("\tforecast\tShow the current weather report according to your region\n") 32 fmt.Printf("\tmoon\tShow the current phase of the Moon\n") 33 } 34 35 func ShowForecast() { 36 query := url + format 44 func ShowForecast(region string, format string) { 45 query := "https://wttr.in/" + region + "?" + format 37 46 resp, err := http.Get(query) 38 47 sanityCheck(err) … … 42 51 fmt.Printf("%s", body) 43 52 } 44 func ShowMoonPhases( ) {45 query := url + "/Moon" + format53 func ShowMoonPhases(format string) { 54 query := "https://wttr.in/" + "moon" + "?" + format 46 55 resp, err := http.Get(query) 47 56 sanityCheck(err)
Note:
See TracChangeset
for help on using the changeset viewer.