1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// 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)
}
}
}
|