grim/wasdead

290c54cfd71a
Parents e3445e602139
Children 5c237823f4c9
Add a database path option to the global command line parser
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/globals/globals.go Fri May 10 23:31:45 2019 -0500
@@ -0,0 +1,5 @@
+package globals
+
+type Globals struct {
+ DatabasePath string `kong:"flag,name='database-path',default='db',help='The path to store the database files'"`
+}
--- a/main.go Fri May 10 23:23:35 2019 -0500
+++ b/main.go Fri May 10 23:31:45 2019 -0500
@@ -5,6 +5,7 @@
"github.com/alecthomas/kong"
+ "bitbucket.org/TheToyz/nowdead/globals"
"bitbucket.org/TheToyz/nowdead/run"
)
@@ -14,12 +15,14 @@
type versionCmd struct{}
-func (c *versionCmd) Run() error {
+func (c *versionCmd) Run(g *globals.Globals) error {
fmt.Printf("wasdead v%s\n", version)
return nil
}
type cli struct {
+ globals.Globals
+
Run run.RunCmd `kong:"cmd,help='Run the bot'"`
Version versionCmd `kong:"cmd,help='Display the version of this program'"`
}
@@ -33,6 +36,6 @@
kong.UsageOnError(),
)
- err := ctx.Run()
+ err := ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}
--- a/run/run.go Fri May 10 23:23:35 2019 -0500
+++ b/run/run.go Fri May 10 23:31:45 2019 -0500
@@ -10,6 +10,7 @@
"bitbucket.org/TheToyz/nowdead/database"
"bitbucket.org/TheToyz/nowdead/discord"
+ "bitbucket.org/TheToyz/nowdead/globals"
"bitbucket.org/TheToyz/nowdead/presence"
"bitbucket.org/TheToyz/nowdead/twitch"
)
@@ -28,8 +29,8 @@
log.SetLevel(log.DebugLevel)
}
-func (r *RunCmd) Run() error {
- if err := database.Open("db"); err != nil {
+func (r *RunCmd) Run(g *globals.Globals) error {
+ if err := database.Open(g.DatabasePath); err != nil {
return err
}
defer database.Close()