2023-04-22 08:25:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-02 05:31:15 +00:00
|
|
|
"context"
|
2023-04-22 08:25:13 +00:00
|
|
|
"flag"
|
2023-05-02 05:31:15 +00:00
|
|
|
"os"
|
2023-05-02 16:27:27 +00:00
|
|
|
"strings"
|
2023-04-22 08:25:13 +00:00
|
|
|
|
2023-05-02 05:31:15 +00:00
|
|
|
"git.wntrmute.dev/kyle/kdhcp/config"
|
2023-05-01 14:37:52 +00:00
|
|
|
"git.wntrmute.dev/kyle/kdhcp/log"
|
2023-05-02 16:27:27 +00:00
|
|
|
"git.wntrmute.dev/kyle/kdhcp/server"
|
2023-05-02 05:31:15 +00:00
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
2023-04-22 08:25:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-05-02 05:31:15 +00:00
|
|
|
var configPath string
|
2023-05-02 16:27:27 +00:00
|
|
|
logLevel := "DEBUG"
|
2023-05-02 05:31:15 +00:00
|
|
|
|
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)
|
|
|
|
log.Setup(logLevel, "kdhcpd")
|
|
|
|
|
2023-05-02 05:31:15 +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()
|
|
|
|
|
2023-05-02 05:31:15 +00:00
|
|
|
return nil
|
|
|
|
},
|
2023-04-22 08:25:13 +00:00
|
|
|
}
|
2023-05-01 14:37:52 +00:00
|
|
|
|
2023-05-02 05:31:15 +00:00
|
|
|
root.ParseAndRun(context.Background(), os.Args[1:])
|
2023-04-22 08:25:13 +00:00
|
|
|
}
|