-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
47 lines (40 loc) · 885 Bytes
/
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
package main
import (
"os"
"github.com/joho/godotenv"
"github.com/psucodervn/go/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/psucodervn/verixilac/cmd/bot"
)
var (
rootCmd = &cobra.Command{
Use: "main",
PersistentPreRun: preRun,
}
envFiles []string
)
func preRun(cmd *cobra.Command, args []string) {
if len(envFiles) == 0 {
if _, err := os.Stat(".env"); err == nil {
envFiles = append(envFiles, ".env")
}
}
if len(envFiles) > 0 {
if err := godotenv.Overload(envFiles...); err != nil {
log.Err(err).Msg("read env files failed")
}
}
logger.InitFromEnv()
}
func init() {
rootCmd.AddCommand(
bot.Command(),
)
rootCmd.PersistentFlags().StringSliceVarP(&envFiles, "envfile", "e", nil, "env files")
}
func main() {
if err := rootCmd.Execute(); err != nil {
log.Fatal().Err(err).Msg("execute failed")
}
}