[6bbceb9] | 1 | // $TheSupernovaDuo: yuuka,v 0.1.1 2023/5/29 18:19:14 yakumo_izuru Exp $
|
---|
| 2 | package main
|
---|
| 3 |
|
---|
| 4 | import (
|
---|
| 5 | "log"
|
---|
| 6 |
|
---|
| 7 | "github.com/integrii/flaggy"
|
---|
| 8 | )
|
---|
| 9 | var (
|
---|
| 10 | format string = "AT"
|
---|
| 11 | region string
|
---|
| 12 | lang string = "en"
|
---|
| 13 | )
|
---|
| 14 | func main() {
|
---|
| 15 | flaggy.SetDescription("Yuuka is yet another client for wttr.in")
|
---|
| 16 | flaggy.SetVersion(FullVersion())
|
---|
| 17 |
|
---|
| 18 | forecastCmd := flaggy.NewSubcommand("forecast")
|
---|
| 19 | forecastCmd.String(&format, "f", "format", "View options")
|
---|
| 20 | forecastCmd.String(®ion, "r", "region", "Where to look at")
|
---|
| 21 | forecastCmd.String(&lang, "l", "language", "Set preferred language")
|
---|
| 22 | forecastCmd.Description = "Check the current forecast of an specific location"
|
---|
| 23 |
|
---|
| 24 | moonCmd := flaggy.NewSubcommand("moon")
|
---|
| 25 | moonCmd.String(&format, "f", "format", "View options")
|
---|
| 26 | moodCmd.String(&lang, "l", "language", "Set preferred language")
|
---|
| 27 | moonCmd.Description = "See what's going on at the Moon"
|
---|
| 28 |
|
---|
| 29 | flaggy.AttachSubcommand(forecastCmd, 1)
|
---|
| 30 | flaggy.AttachSubcommand(moonCmd, 1)
|
---|
| 31 |
|
---|
| 32 | flaggy.Parse()
|
---|
| 33 |
|
---|
| 34 | if forecastCmd.Used {
|
---|
| 35 | ShowForecast(region, format, lang)
|
---|
| 36 | } else if moonCmd.Used {
|
---|
| 37 | ShowMoonPhases(format, lang)
|
---|
| 38 | } else {
|
---|
| 39 | flaggy.ShowHelpAndExit("A subcommand is required")
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | func sanityCheck(err error) {
|
---|
| 43 | if err != nil {
|
---|
| 44 | log.Fatal(err)
|
---|
| 45 | }
|
---|
| 46 | }
|
---|