-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmain.go
50 lines (40 loc) · 1.17 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
package main
//go:generate go run generate.go
//go:generate gofmt -s -w autogen/db/postgres/db_sql_migration.go
import (
"flag"
"fmt"
"os"
"github.com/ncarlier/readflow/cmd"
"github.com/ncarlier/readflow/internal/config"
"github.com/ncarlier/readflow/pkg/logger"
_ "github.com/ncarlier/readflow/cmd/all"
)
func main() {
// parse command line
flag.Parse()
// load configuration
conf := config.NewConfig()
if cmd.ConfigFlag != "" {
if err := conf.LoadFile(cmd.ConfigFlag); err != nil {
logger.Fatal().Err(err).Str("filename", cmd.ConfigFlag).Msg("unable to load configuration file")
}
}
// export configurations vars
config.ExportVars(conf)
// configure the logger
logger.Configure(conf.Log.Level, conf.Log.Format, conf.Integration.Sentry.DSN)
args := flag.Args()
commandLabel, idx := cmd.GetFirstCommand(args)
if command, ok := cmd.Commands[commandLabel]; ok {
if err := command.Exec(args[idx+1:], conf); err != nil {
logger.Fatal().Err(err).Str("command", commandLabel).Msg("error during command execution")
}
} else {
if commandLabel != "" {
fmt.Fprintf(os.Stderr, "undefined command: %s\n", commandLabel)
}
flag.Usage()
os.Exit(0)
}
}