forked from skeema/skeema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skeema.go
63 lines (51 loc) · 1.56 KB
/
skeema.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
package main
import (
"fmt"
"os"
"runtime/debug"
log "github.com/sirupsen/logrus"
"github.com/skeema/mybase"
"github.com/skeema/skeema/util"
"github.com/skeema/skeema/workspace"
)
const rootDesc = `Skeema is a MySQL schema management tool. It allows you to export a database
schema to the filesystem, and apply online schema changes by modifying files.`
// Globals overridden by GoReleaser's ldflags
var (
version = "1.4.5"
commit = "unknown"
date = "unknown"
)
// CommandSuite is the root command. It is global so that subcommands can be
// added to it via init() functions in each subcommand's source file.
var CommandSuite = mybase.NewCommandSuite("skeema", versionString(), rootDesc)
func main() {
// Add global options. Sub-commands may override these when needed.
util.AddGlobalOptions(CommandSuite)
var cfg *mybase.Config
defer func() {
if iface := recover(); iface != nil {
if cfg != nil && cfg.GetBool("debug") {
log.Debug(string(debug.Stack()))
}
Exit(NewExitValue(CodeFatalError, fmt.Sprint(iface)))
}
}()
cfg, err := mybase.ParseCLI(CommandSuite, os.Args)
if err != nil {
Exit(NewExitValue(CodeBadConfig, err.Error()))
}
util.AddGlobalConfigFiles(cfg)
if err := util.ProcessSpecialGlobalOptions(cfg); err != nil {
Exit(NewExitValue(CodeBadConfig, err.Error()))
}
err = cfg.HandleCommand()
workspace.Shutdown()
Exit(err)
}
func versionString() string {
if commit == "unknown" {
return fmt.Sprintf("%s (snapshot build from source)", version)
}
return fmt.Sprintf("%s, commit %s, released %s", version, commit, date)
}