forked from supabase/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_cmd.go
60 lines (47 loc) · 1.59 KB
/
root_cmd.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
package cmd
import (
"context"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/supabase/auth/internal/conf"
"github.com/supabase/auth/internal/observability"
)
var configFile = ""
var rootCmd = cobra.Command{
Use: "gotrue",
Run: func(cmd *cobra.Command, args []string) {
migrate(cmd, args)
serve(cmd.Context())
},
}
// RootCommand will setup and return the root command
func RootCommand() *cobra.Command {
rootCmd.AddCommand(&serveCmd, &migrateCmd, &versionCmd, adminCmd())
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "the config file to use")
return &rootCmd
}
func loadGlobalConfig(ctx context.Context) *conf.GlobalConfiguration {
if ctx == nil {
panic("context must not be nil")
}
config, err := conf.LoadGlobal(configFile)
if err != nil {
logrus.Fatalf("Failed to load configuration: %+v", err)
}
if err := observability.ConfigureLogging(&config.Logging); err != nil {
logrus.WithError(err).Error("unable to configure logging")
}
if err := observability.ConfigureTracing(ctx, &config.Tracing); err != nil {
logrus.WithError(err).Error("unable to configure tracing")
}
if err := observability.ConfigureMetrics(ctx, &config.Metrics); err != nil {
logrus.WithError(err).Error("unable to configure metrics")
}
if err := observability.ConfigureProfiler(ctx, &config.Profiler); err != nil {
logrus.WithError(err).Error("unable to configure profiler")
}
return config
}
func execWithConfigAndArgs(cmd *cobra.Command, fn func(config *conf.GlobalConfiguration, args []string), args []string) {
fn(loadGlobalConfig(cmd.Context()), args)
}