-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
139 lines (117 loc) · 3.33 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Copyright © 2022-2024 Bopmatic, LLC. All Rights Reserved.
*
* See LICENSE file at the root of this package for license terms
*/
package main
import (
"flag"
"fmt"
"os"
"runtime"
"strings"
"time"
_ "embed"
bopsdk "github.com/bopmatic/sdk/golang"
"github.com/bopmatic/sdk/golang/pb"
)
type commonOpts struct {
projectFilename string
projectId string
packageId string
deployId string
serviceName string
startTime string
endTime string
}
var subCommandTab = map[string]func(args []string){
"project": projMain,
"package": pkgMain,
"deploy": deployMain,
"help": helpMain,
"config": configMain,
"version": versionMain,
"upgrade": upgradeMain,
"logs": logsMain,
}
const (
ExamplesDir = "/bopmatic/examples"
DefaultTemplate = "golang/helloworld"
ClientTemplateSubdir = "client"
SiteAssetsSubdir = "site_assets"
// update Makefile brewversion target if changing this value
BrewVersionSuffix = "b"
)
func printExampleCurl(descReply *pb.DescribePackageReply) {
// @todo re-implement w/ ListServices() && DescribeService()
}
func unixTime2Local(msecs uint64) time.Time {
return time.UnixMilli(int64(msecs))
}
func unixTime2Utc(msecs uint64) time.Time {
return unixTime2Local(msecs).UTC()
}
func unixTime2UtcStr(msecs uint64) string {
if msecs == 0 {
return ""
}
return unixTime2Utc(msecs).String()
}
//go:embed help.txt
var helpText string
func helpMain(args []string) {
fmt.Printf(helpText)
}
func setCommonFlags(f *flag.FlagSet, o *commonOpts) {
f.StringVar(&o.projectFilename, "projfile", bopsdk.DefaultProjectFilename,
"Bopmatic project filename")
f.StringVar(&o.projectId, "projid", "", "Bopmatic project id")
f.StringVar(&o.packageId, "pkgid", "",
"Bopmatic project package identifier")
f.StringVar(&o.deployId, "deployid", "",
"Bopmatic deployment identifier")
f.StringVar(&o.serviceName, "svcname", "",
"Name of a service within your Bopmatic project")
f.StringVar(&o.startTime, "starttime", "",
"The starting time in UTC to query; defaults to 48 hours ago.")
f.StringVar(&o.endTime, "endtime", "",
"The ending time in UTC to query; defaults to now.")
}
func checkAndPrintArchWarning() bool {
if runtime.GOARCH != "amd64" {
if runtime.GOOS == "darwin" {
fmt.Fprintf(os.Stderr, "*WARN*: bopmatic's build container is known not to run well on M1 based Macs; please try on a 64-bit Intel/AMD based system if possible.\n")
} else {
fmt.Fprintf(os.Stderr, "*WARN*: bopmatic's build container has not been tested on your CPU (%v); please try on a 64-bit Intel/AMD based system if possible.\n",
runtime.GOARCH)
}
return true
}
return false
}
func main() {
versionText = strings.Split(versionText, "\n")[0]
exitStatus := 0
printedUpgradeCLIWarning := checkAndPrintUpgradeCLIWarning()
printedUpgradeContainerWarning := checkAndPrintUpgradeContainerWarning()
printedArchWarning := checkAndPrintArchWarning()
if printedUpgradeCLIWarning || printedUpgradeContainerWarning || printedArchWarning {
fmt.Fprintf(os.Stderr, "\n")
}
subCommandName := "help"
if len(os.Args) > 1 {
subCommandName = os.Args[1]
} else {
exitStatus = 1
}
subCommand, ok := subCommandTab[subCommandName]
if !ok {
subCommand = helpMain
exitStatus = 1
}
var args []string
if len(os.Args) > 2 {
args = os.Args[2:]
}
subCommand(args)
os.Exit(exitStatus)
}