-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgvacli.go
66 lines (57 loc) · 1.83 KB
/
gvacli.go
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
65
66
package main
import (
"log"
flag "github.com/spf13/pflag"
)
// Some useful timestamps and values
var (
APITimeout int
APIUrl string
Arrivals bool
BigDelayMinutes float64 = 60
CacheTTLSeconds float64 = 60
Departures bool
FairDelayMinutes float64 = 30
JSONTimeFormat = "2006-01-02 15:04:05"
LongDisplayTimeFormat = "02/01 15:04"
NoCache bool
ShortDisplayTimeFormat = "15:04"
ShowAllFlights bool
ShowCodeShare bool
)
func init() {
flag.StringVar(&APIUrl, "api-url", "https://app4airport.com/api/flights", "API URL of remote webservice")
flag.IntVar(&APITimeout, "api-timeout", 10, "API reply timeout (in seconds)")
flag.BoolVar(&ShowCodeShare, "code-shares", false, "Show code shares")
flag.BoolVar(&Departures, "departures", false, "Show departures")
flag.BoolVar(&Arrivals, "arrivals", false, "Show arrivals")
flag.BoolVar(&ShowAllFlights, "all-flights", false, "Show all flights, despite of the status")
flag.BoolVar(&NoCache, "no-cache", false, "Ignored cached data")
flag.Parse()
}
func main() {
// If we hide everything, show arrivals by default
if !Departures && !Arrivals {
Arrivals = true
}
info := NewFlightInfos()
if err := info.GetData(); err != nil {
log.Fatalf("Unable to fetch data from remote API: %s", err)
}
if Departures {
depTable := info.PrepareDeparturesTable(info.Flights.Departures)
info.PrintTable(
"Departures",
[]string{"Sched", "Exp", "Dest", "Flight", "Airline", "Gate", "Aircraft", "Reg", "Status"},
depTable,
)
}
if Arrivals {
arrTable := info.PrepareArrivalsTable(info.Flights.Arrivals)
info.PrintTable(
"Arrivals",
[]string{"Sched", "Exp", "Dep", "Source", "Flight", "Airline", "Belt", "Aircraft", "Reg", "Status"},
arrTable,
)
}
}