This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (58 loc) · 1.5 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
package main
import (
"fmt"
"os"
"time"
"github.com/urfave/cli/v2"
)
var (
// these variables are populated by Goreleaser when releasing
version = "unknown"
commit = "-dirty-"
date = time.Now().Format("2006-01-02")
// TODO: Adjust app name
appName = "go-bootstrap"
appLongName = "a generic bootstrapping project"
// TODO: Adjust or clear env var prefix
// envPrefix is the global prefix to use for the keys in environment variables.
// Include a delimiter like `_` if required.
envPrefix = "BOOTSTRAP_"
)
func main() {
app := newApp()
err := app.Run(os.Args)
// If required flags aren't set, it will return with error before we could set up logging
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func newApp() *cli.App {
app := &cli.App{
Name: appName,
Usage: appLongName,
Version: fmt.Sprintf("%s, revision=%s, date=%s", version, commit, date),
Before: setupLogging,
Flags: []cli.Flag{
newLogLevelFlag(),
newLogFormatFlag(),
},
Commands: []*cli.Command{
newExampleCommand(),
},
}
return app
}
// TODO: Remove env() and envVars() if not using an environment variable prefix.
// env combines envPrefix with given suffix delimited by underscore.
func env(suffix string) string {
return envPrefix + suffix
}
// envVars combines envPrefix with each given suffix delimited by underscore.
func envVars(suffixes ...string) []string {
arr := make([]string, len(suffixes))
for i := range suffixes {
arr[i] = env(suffixes[i])
}
return arr
}