-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (31 loc) · 996 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
package main
import (
"github.com/alecthomas/kong"
"github.com/annybs/shorty/internal/cli"
"github.com/rs/zerolog"
"github.com/spf13/viper"
)
func main() {
// Initialise config from environment
config := viper.New()
config.SetEnvPrefix("shorty")
config.SetDefault("all_path", "/*")
config.SetDefault("database_path", ".shorty")
config.SetDefault("port", "3000")
config.SetDefault("url", "http://localhost:3000")
config.AutomaticEnv()
// Create logger
log := zerolog.New(zerolog.NewConsoleWriter()).With().Timestamp().Logger()
// Initialise and run CLI
vars := kong.Vars{
"all_path": config.GetString("all_path"),
"database_path": config.GetString("database_path"),
"host": config.GetString("host"),
"port": config.GetString("port"),
"token": config.GetString("token"),
"url": config.GetString("url"),
}
ctx := kong.Parse(&cli.CLI{}, vars)
err := ctx.Run(&cli.Context{Config: config, Log: log})
ctx.FatalIfErrorf(err)
}