main.go 912 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "fmt"
  4. "git.linuxforward.com/byom/byom-core/app"
  5. "git.linuxforward.com/byom/byom-core/config"
  6. "github.com/alecthomas/kong"
  7. )
  8. var (
  9. version = "0.0.1-dev"
  10. commit = "none"
  11. date = "unknown"
  12. )
  13. var cli struct {
  14. Serve ServeCmd `cmd:"serve" help:"Run the server"`
  15. Version VersionCmd `cmd:"version" help:"Print version information"`
  16. }
  17. type ServeCmd struct {
  18. Config string `type:"path" help:"Path to the configuration file." default:"config.yaml"`
  19. }
  20. func (c *ServeCmd) Run() error {
  21. cnf, err := config.ReadConfig(c.Config)
  22. if err != nil {
  23. return err
  24. }
  25. app, err := app.NewApp(cnf)
  26. if err != nil {
  27. return err
  28. }
  29. return app.Run()
  30. }
  31. type VersionCmd struct{}
  32. func (c *VersionCmd) Run() error {
  33. fmt.Printf("byom-core %s, commit %s, built at %s", version, commit, date)
  34. return nil
  35. }
  36. func main() {
  37. ctx := kong.Parse(&cli)
  38. err := ctx.Run()
  39. ctx.FatalIfErrorf(err)
  40. }