Changeset 2 in code for trunk/main.go


Ignore:
Timestamp:
May 29, 2023, 10:44:48 PM (2 years ago)
Author:
Izuru Yakumo
Message:

Power levels keep increasing widly -- to be expected

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/main.go

    r1 r2  
    1 // $TheSupernovaDuo: yuuka,v master 2023/5/29 17:54:15 yakumo_izuru Exp $
     1// $TheSupernovaDuo: yuuka,v 0.1.1 2023/5/29 18:19:14 yakumo_izuru Exp $
    22package main
    33
     
    77        "log"
    88        "net/http"
    9         "os"
     9
     10        "github.com/integrii/flaggy"
    1011)
    1112var (
    12         format = "?AT"
    13         url = "https://wttr.in"
     13        format string = "AT"
     14        region string
    1415)
    1516func 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(&region, "r", "region", "Where to look at")
     23        forecastCmd.Description = "Check the forecast for a specified location"
    1924
    20         cmd := os.Args[1]
     25        flaggy.AttachSubcommand(forecastCmd, 1)
    2126
    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")
    2742        }
    2843}
    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
     44func ShowForecast(region string, format string) {
     45        query := "https://wttr.in/" + region + "?" + format
    3746        resp, err := http.Get(query)
    3847        sanityCheck(err)
     
    4251        fmt.Printf("%s", body)
    4352}
    44 func ShowMoonPhases() {
    45         query := url + "/Moon" + format
     53func ShowMoonPhases(format string) {
     54        query := "https://wttr.in/" + "moon" + "?" + format
    4655        resp, err := http.Get(query)
    4756        sanityCheck(err)
Note: See TracChangeset for help on using the changeset viewer.