kdhcp/cmd/kdhcpd/main.go

48 lines
856 B
Go
Raw Normal View History

2023-04-22 08:25:13 +00:00
package main
import (
"context"
2023-04-22 08:25:13 +00:00
"flag"
"os"
2023-05-02 16:27:27 +00:00
"strings"
2023-04-22 08:25:13 +00:00
2023-05-09 07:28:54 +00:00
"git.wntrmute.dev/kyle/goutils/log"
"git.wntrmute.dev/kyle/kdhcp/config"
2023-05-02 16:27:27 +00:00
"git.wntrmute.dev/kyle/kdhcp/server"
"github.com/peterbourgon/ff/v3/ffcli"
2023-04-22 08:25:13 +00:00
)
func main() {
var configPath string
2023-05-02 16:27:27 +00:00
logLevel := "DEBUG"
2023-05-02 16:27:27 +00:00
flag.StringVar(&configPath, "f", "", "path to `config file`")
flag.StringVar(&logLevel, "l", logLevel, "log level")
2023-04-22 08:25:13 +00:00
flag.Parse()
2023-05-02 16:27:27 +00:00
logLevel = strings.ToUpper(logLevel)
2023-05-05 07:13:46 +00:00
log.Setup(log.DefaultDebugOptions("kdhcpd", false))
2023-05-02 16:27:27 +00:00
root := &ffcli.Command{
Exec: func(ctx context.Context, args []string) error {
cfg, err := config.Load(configPath)
if err != nil {
log.Fatal(err)
}
2023-05-01 14:37:52 +00:00
2023-05-02 16:27:27 +00:00
srv, err := server.New(cfg)
if err != nil {
log.Fatal(err)
}
defer srv.Close()
srv.Listen()
return nil
},
2023-04-22 08:25:13 +00:00
}
2023-05-01 14:37:52 +00:00
root.ParseAndRun(context.Background(), os.Args[1:])
2023-04-22 08:25:13 +00:00
}