// main.go - Main application package main import ( "encoding/json" "flag" "fmt" "os" "os/signal" "syscall" "time" ) func main() { 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() // Get initial forecast client := NewFMIClient() response, err := client.GetForecast(*location) if err != nil { fmt.Fprintf(os.Stderr, "Error: %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) } } }