main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "git.beejay.kim/WatchDog/ward/app/daemon"
  4. "git.beejay.kim/WatchDog/ward/version"
  5. "github.com/rs/zerolog"
  6. "github.com/rs/zerolog/log"
  7. "github.com/urfave/cli/v2"
  8. "os"
  9. "time"
  10. )
  11. var app *cli.App
  12. func init() {
  13. // Default log level is info, unless debug flag is present
  14. zerolog.SetGlobalLevel(zerolog.InfoLevel)
  15. zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
  16. log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
  17. app = &cli.App{
  18. Name: version.Name,
  19. Version: version.BuildVersion,
  20. EnableBashCompletion: true,
  21. Compiled: time.Now(),
  22. Authors: []*cli.Author{
  23. {
  24. Name: "BeeJay Kim",
  25. Email: "i@beejay.kim",
  26. },
  27. },
  28. Copyright: "(c) 2024 BeeJay Kim",
  29. Flags: []cli.Flag{
  30. &cli.BoolFlag{
  31. Name: "debug",
  32. Usage: "sets log level to debug",
  33. Aliases: []string{"D"},
  34. Action: func(ctx *cli.Context, debug bool) error {
  35. zerolog.SetGlobalLevel(zerolog.DebugLevel)
  36. return nil
  37. },
  38. },
  39. },
  40. Commands: []*cli.Command{
  41. &daemon.Command,
  42. },
  43. }
  44. }
  45. func main() {
  46. if err := app.Run(os.Args); err != nil {
  47. log.Err(err).Send()
  48. }
  49. }