-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
96 lines (79 loc) · 1.96 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
89
90
91
92
93
94
95
96
package main
import (
"log"
"os"
"git.blob42.xyz/blob42/hugobot/v3/config"
"git.blob42.xyz/blob42/hugobot/v3/logging"
"github.com/gobuffalo/flect"
altsrc "github.com/urfave/cli/altsrc"
cli "gopkg.in/urfave/cli.v1"
)
func tearDown() {
DB.Handle.Close()
logging.Close()
}
func main() {
defer tearDown()
app := cli.NewApp()
app.Name = "hugobot"
app.Version = "1.0"
flags := []cli.Flag{
altsrc.NewStringFlag(cli.StringFlag{
Name: "website-path",
Usage: "`PATH` to hugo project",
EnvVar: "WEBSITE_PATH",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "github-access-token",
Usage: "Github API Access Token",
EnvVar: "GH_ACCESS_TOKEN",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "rel-bitcoin-addr-content-path",
Usage: "path to bitcoin data relative to hugo path",
}),
altsrc.NewIntFlag(cli.IntFlag{
Name: "api-port",
Usage: "default bot api port",
}),
cli.StringFlag{
Name: "config",
Value: "config.toml",
Usage: "TOML config `FILE` path",
},
}
app.Before = func(c *cli.Context) error {
err := altsrc.InitInputSourceWithContext(flags,
altsrc.NewTomlSourceFromFlagFunc("config"))(c)
if err != nil {
return err
}
for _, conf := range c.GlobalFlagNames() {
// find corresponding flag
for _, flag := range flags {
if flag.GetName() == conf {
switch flag.(type) {
case cli.StringFlag:
err = config.RegisterConf(flect.Pascalize(conf), c.GlobalString(conf))
case *altsrc.StringFlag:
err = config.RegisterConf(flect.Pascalize(conf), c.GlobalString(conf))
case cli.IntFlag:
err = config.RegisterConf(flect.Pascalize(conf), c.GlobalInt(conf))
case *altsrc.IntFlag:
err = config.RegisterConf(flect.Pascalize(conf), c.GlobalInt(conf))
}
}
}
}
return err
}
app.Flags = flags
app.Commands = []cli.Command{
startServerCmd,
exportCmdGrp,
feedsCmdGroup,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}