diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 52 |
1 files changed, 43 insertions, 9 deletions
@@ -1,4 +1,4 @@ -// main.go - Main application entry point +// main.go - Main application package main import ( @@ -6,13 +6,22 @@ import ( "flag" "fmt" "os" + "os/signal" + "syscall" + "time" ) func main() { - location := flag.String("place", "Helsinki", "Location for the forecast") + var ( + location = flag.String("place", "Helsinki", "Location for the forecast") + tuiMode = flag.Bool("tui", true, "Run in TUI mode") + jsonMode = flag.Bool("json", false, "Output as JSON") + days = flag.Int("days", 1, "Number of days to forecast (1-3)") + refresh = flag.Int("refresh", 0, "Refresh interval in minutes (0 for no refresh)") + ) flag.Parse() - // Create client and get forecast + // Get initial forecast client := NewFMIClient() response, err := client.GetForecast(*location) if err != nil { @@ -20,11 +29,36 @@ func main() { os.Exit(1) } - // Output JSON - jsonData, err := json.MarshalIndent(response, "", " ") - if err != nil { - fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err) - os.Exit(1) + // JSON output mode + if *jsonMode { + jsonData, err := json.MarshalIndent(response, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err) + os.Exit(1) + } + fmt.Println(string(jsonData)) + return + } + + // TUI mode + if *tuiMode { + model := NewModel(response, *location, *days) + if *refresh > 0 { + model.SetRefreshInterval(time.Duration(*refresh) * time.Minute) + } + + // Handle interrupts + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + go func() { + <-sigChan + model.Quit() + }() + + // Run the TUI + if err := model.Run(); err != nil { + fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err) + os.Exit(1) + } } - fmt.Println(string(jsonData)) } |
