-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (74 loc) · 2.05 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
package main
import (
"fmt"
"os"
"strings"
"github.com/atrox/cain/commands"
"github.com/atrox/cain/config"
"github.com/atrox/cain/updater"
"github.com/urfave/cli"
)
var (
version = "master"
appUpdater *updater.Updater
)
func init() {
updater.Version = version
}
func main() {
cmds := []*cli.Command{
commands.SetupCommand,
commands.RunCommand,
commands.UpdateCommand,
}
app := &cli.App{
Name: "cain",
HelpName: "cain",
Usage: "automated media management",
Version: version,
Authors: []*cli.Author{{Name: "Atrox", Email: "mail@atrox.me"}},
Commands: cmds,
Before: before,
After: after,
}
app.Run(os.Args)
}
func before(c *cli.Context) error {
// get configuration
conf := new(config.Config)
config.Storage.Get(conf)
if !conf.HideBanner {
fmt.Println(logo)
}
// check only for updates if binary is versioned
if version != "master" {
// check for updates in background
appUpdater = updater.New(conf.AutoUpdate)
}
return nil
}
func after(c *cli.Context) error {
if appUpdater == nil {
return nil
}
_, err := appUpdater.Run()
if err != nil {
return cli.Exit(err, 1)
}
return nil
}
var logo = strings.TrimLeft(fmt.Sprintf(`
_ _ _ _
/\ \ / /\ /\ \ /\ \ _
/ \ \ / / \ \ \ \ / \ \ /\_\
/ /\ \ \ / / /\ \ /\ \_\ / /\ \ \_/ / /
/ / /\ \ \ / / /\ \ \ / /\/_/ / / /\ \___/ /
/ / / \ \_\ / / / \ \ \ / / / / / / \/____/
/ / / \/_/ / / /___/ /\ \ / / / / / / / / /
/ / / / / /_____/ /\ \ / / / / / / / / /
/ / /________ / /_________/\ \ \ ___/ / /__ / / / / / /
/ / /_________\/ / /_ __\ \_\/\__\/_/___\/ / / / / /
\/____________/\_\___\ /____/_/\/_________/\/_/ \/_/
============================================================
Version %s by Atrox.ME
`, version), "\n")