-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (38 loc) · 1.02 KB
/
main.go
File metadata and controls
49 lines (38 loc) · 1.02 KB
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
package main
import (
"fmt"
"os"
"github.com/ipfs-shipyard/equinix-billing-tools/cmd"
"github.com/ipfs-shipyard/equinix-billing-tools/equinix"
)
func main() {
commands := map[string]func(equinix.Equinix) cmd.Command{
"cost_summary": cmd.CostSummary,
"bigquery": cmd.UploadToBigquery,
}
equinixToken := os.Getenv("EQUINIX_TOKEN")
if len(equinixToken) == 0 {
fmt.Fprintf(os.Stderr, "EQUINIX_TOKEN environment variable is not set")
os.Exit(1)
}
eq := equinix.Equinix{
Token: equinixToken,
}
if len(os.Args) == 1 {
fmt.Fprintf(os.Stderr, "Usage: %s <subcommand> [<options>]\nValid subcommands: \n", os.Args[0])
printSubcommands(commands)
os.Exit(1)
}
command, found := commands[os.Args[1]]
if !found {
fmt.Fprintf(os.Stderr, "Invalid subcommand %s. Valid subcommands: \n", os.Args[1])
printSubcommands(commands)
os.Exit(1)
}
command(eq).Run()
}
func printSubcommands(commands map[string]func(equinix.Equinix) cmd.Command) {
for k := range commands {
fmt.Fprintf(os.Stderr, " %s\n", k)
}
}