-
Notifications
You must be signed in to change notification settings - Fork 24
/
ezbookkeeping.go
89 lines (71 loc) · 1.83 KB
/
ezbookkeeping.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
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli/v2"
"github.com/mayswind/ezbookkeeping/cmd"
"github.com/mayswind/ezbookkeeping/pkg/settings"
"github.com/mayswind/ezbookkeeping/pkg/utils"
)
var (
// Version holds the version of this execution program
Version string
// CommitHash holds the git commit hash of this execution program's source code
CommitHash string
// BuildUnixTime holds the time when starting building this execution program
BuildUnixTime string
)
func main() {
settings.Version = Version
settings.CommitHash = CommitHash
app := &cli.App{
Name: "ezBookkeeping",
Usage: "A lightweight personal bookkeeping app hosted by yourself.",
Version: GetFullVersion(),
Commands: []*cli.Command{
cmd.WebServer,
cmd.Database,
cmd.UserData,
cmd.CronJobs,
cmd.SecurityUtils,
cmd.Utilities,
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf-path",
Usage: "Custom config `FILE` path",
},
&cli.BoolFlag{
Name: "no-boot-log",
Usage: "Disable boot log",
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatalf("Failed to run ezBookkeeping with %s: %v", os.Args, err)
}
}
// GetFullVersion returns the full version
func GetFullVersion() string {
fullVersion := "Local Build"
if Version != "" {
fullVersion = Version
}
additionalInfos := make([]string, 0, 2)
if CommitHash != "" {
additionalInfos = append(additionalInfos, "commit "+CommitHash)
}
if BuildUnixTime != "" {
unixTime, err := utils.StringToInt64(BuildUnixTime)
if unixTime > 0 && err == nil {
additionalInfos = append(additionalInfos, "build time "+utils.FormatUnixTimeToLongDateTimeInServerTimezone(unixTime))
}
}
if len(additionalInfos) > 0 {
fullVersion = fmt.Sprintf("%s (%s)", fullVersion, strings.Join(additionalInfos, ", "))
}
return fullVersion
}