-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
74 lines (64 loc) · 1.68 KB
/
main.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
67
68
69
70
71
72
73
74
// main
package main
import (
"flag"
"fmt"
_ "image/gif"
_ "image/jpeg"
"os"
"github.com/otiai10/amesh/cli"
"github.com/otiai10/amesh/lib/tenki"
"github.com/otiai10/gat/render"
)
const version = "v1.4.0"
var (
geo, mask bool
usepix bool
scale float64
// 以下、タイムラプスでのみ有効
lapse bool
minutes int
delay int
loop bool
)
func setup() {
flag.BoolVar(&lapse, "a", false, "タイムラプス表示")
flag.IntVar(&minutes, "m", 40, "タイムラプスの取得直近時間(分)")
flag.IntVar(&delay, "d", 200, "タイムラプスアニメーションのfps(msec)")
flag.BoolVar(&loop, "l", false, "タイムラプスアニメーションをループ表示")
flag.BoolVar(&geo, "g", true, "地形を描画")
flag.BoolVar(&mask, "b", true, "県境を描画")
flag.BoolVar(&usepix, "p", false, "iTermであってもピクセル画で表示")
flag.Float64Var(&scale, "s", 1.2, "表示拡大倍率")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "東京アメッシュをCLIに表示するコマンドです。(%v)\n利用可能なオプション:\n", version)
flag.PrintDefaults()
}
flag.Parse()
}
func main() {
setup()
renderer := render.GetDefaultRenderer()
if usepix {
renderer = &render.CellGrid{}
}
renderer.SetScale(scale)
subcommand := flag.Arg(0)
switch loc := tenki.GetLocation(subcommand); {
case loc != nil:
onerror(cli.Tenki(renderer, loc))
case subcommand == "typhoon":
onerror(cli.Typhoon(renderer))
case lapse:
onerror(cli.Timelapse(renderer, minutes, delay, loop))
default:
onerror(cli.Amesh(renderer, geo, mask))
}
}
func onerror(err error) {
if err == nil {
return
}
fmt.Println(err)
os.Exit(1)
}