-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudcash.go
89 lines (76 loc) · 1.75 KB
/
cloudcash.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"runtime"
"flag"
"fmt"
"text/template"
"github.com/mrusme/cloudcash/cloud"
"github.com/mrusme/cloudcash/cloud/aws"
"github.com/mrusme/cloudcash/cloud/digitalocean"
"github.com/mrusme/cloudcash/cloud/github"
"github.com/mrusme/cloudcash/cloud/vultr"
"github.com/mrusme/cloudcash/lib"
"github.com/mrusme/cloudcash/menu"
)
func main() {
var waybarPango bool = false
var jsonOut bool = false
var menuMode bool = false
flag.BoolVar(
&jsonOut,
"json",
false,
"Output JSON",
)
flag.BoolVar(
&waybarPango,
"waybar-pango",
false,
"Output Waybar compatible JSON with Pango template per service",
)
flag.BoolVar(
&menuMode,
"menu-mode",
false,
"Run as menubar app (only on macOS)",
)
flag.Parse()
if menuMode == true {
runtime.LockOSThread()
}
config, err := lib.Cfg()
if err != nil {
panic(err)
}
c := cloud.New(&config)
if s, err := vultr.New(&config); err == nil {
c.AddService("vultr", "Vultr", s)
}
if s, err := digitalocean.New(&config); err == nil {
c.AddService("digitalocean", "DigitalOcean", s)
}
if s, err := aws.New(&config); err == nil {
c.AddService("aws", "AWS", s)
}
if s, err := github.New(&config); err == nil {
c.AddService("github", "GitHub", s)
}
c.RefreshAll()
if menuMode == true ||
config.Menu.IsDefault == true {
t := template.Must(template.New("menu").Parse(config.Menu.Template))
menu.Run(c, t)
return
} else {
if jsonOut == true {
fmt.Print(c.JSON())
} else if waybarPango == true {
fmt.Print(c.Waybar(
template.Must(template.New("waybar").Parse(config.Waybar.Pango)),
))
} else {
fmt.Print(c.Text())
}
}
return
}