-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathroot_cmd.go
52 lines (42 loc) · 1.39 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
package cmd
import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/netlify/gotrue/conf"
)
var configFile = ""
var rootCmd = cobra.Command{
Use: "gotrue",
Run: func(cmd *cobra.Command, args []string) {
migrate(&migrateCmd, args)
execWithConfig(cmd, serve)
},
}
// RootCommand will setup and return the root command
func RootCommand() *cobra.Command {
rootCmd.AddCommand(&serveCmd, &migrateCmd, &multiCmd, &versionCmd, adminCmd())
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "the config file to use")
return &rootCmd
}
func execWithConfig(cmd *cobra.Command, fn func(globalConfig *conf.GlobalConfiguration, config *conf.Configuration)) {
globalConfig, err := conf.LoadGlobal(configFile)
if err != nil {
logrus.Fatalf("Failed to load configuration: %+v", err)
}
config, err := conf.LoadConfig(configFile)
if err != nil {
logrus.Fatalf("Failed to load configuration: %+v", err)
}
fn(globalConfig, config)
}
func execWithConfigAndArgs(cmd *cobra.Command, fn func(globalConfig *conf.GlobalConfiguration, config *conf.Configuration, args []string), args []string) {
globalConfig, err := conf.LoadGlobal(configFile)
if err != nil {
logrus.Fatalf("Failed to load configuration: %+v", err)
}
config, err := conf.LoadConfig(configFile)
if err != nil {
logrus.Fatalf("Failed to load configuration: %+v", err)
}
fn(globalConfig, config, args)
}