forked from davecheney/pub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (45 loc) · 1.53 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
package main
import (
"os"
"golang.org/x/exp/slog"
"github.com/alecthomas/kong"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type Context struct {
Debug bool
Logger *slog.Logger
gorm.Config
gorm.Dialector
}
var cli struct {
LogSQL bool `help:"Log SQL queries."`
DSN string `help:"data source name" default:"pub:pub@tcp(localhost:3306)/pub"`
AutoMigrate AutoMigrateCmd `cmd:"" help:"Automigrate the database."`
CreateAccount CreateAccountCmd `cmd:"" help:"Create a new account."`
CreateInstance CreateInstanceCmd `cmd:"" help:"Create a new instance."`
DeleteAccount DeleteAccountCmd `cmd:"" help:"Delete an account."`
FetchActor FetchActorCmd `cmd:"" help:"Fetch an actor."`
HouseKeeping HouseKeepingCmd `cmd:"" help:"Perform housekeeping."`
Serve ServeCmd `cmd:"" help:"Serve a local web server."`
ShowActor ShowActorCmd `cmd:"" help:"Display an actor."`
SynchroniseFollowers SynchroniseFollowersCmd `cmd:"" help:"Synchronise followers."`
Follow FollowCmd `cmd:"" help:"Follow an object."`
}
func main() {
ctx := kong.Parse(&cli)
err := ctx.Run(&Context{
Debug: cli.LogSQL,
Logger: slog.New(slog.NewTextHandler(os.Stderr)),
Config: gorm.Config{
Logger: logger.Default.LogMode(func() logger.LogLevel {
if cli.LogSQL {
return logger.Info
}
return logger.Warn
}()),
},
Dialector: newDialector(cli.DSN),
})
ctx.FatalIfErrorf(err)
}