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
|
package main
import (
"context"
"os"
"time"
"github.com/grindlemire/gothem-stack/pkg/log"
"github.com/pkg/errors"
"go.uber.org/zap"
)
func init() {
log.InitGlobal()
}
type Config struct {
Env string `envconfig:"env" default:"local"`
Args []string `envconfig:"args" default:""`
}
func withBoilerplate(fn func(context.Context) error) (err error) {
start := time.Now()
defer func() {
if r := recover(); r != nil {
err = errors.Errorf("%s", r)
}
finish(start, err)
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
return fn(WithConfig(ctx, os.Args[2:]...))
}
func Install() error { return withBoilerplate(install) }
func Tidy() error { return withBoilerplate(tidy) }
func Build() error { return withBoilerplate(build) }
func Run() error { return withBoilerplate(run) }
func Templ() error { return withBoilerplate(templ) }
func Deploy() error { return withBoilerplate(deploy) }
func Auth() error { return withBoilerplate(auth) }
func Release() error { return withBoilerplate(release) }
func Destroy() error { return withBoilerplate(destroy) }
func finish(start time.Time, err error) {
zap.S().Infof("elapsed time: %s", time.Since(start))
if err != nil {
zap.S().Fatal(err)
}
os.Exit(0)
}
|