main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "runtime"
  6. "github.com/alecthomas/kong"
  7. "goa.design/clue/log"
  8. )
  9. type (
  10. CLI struct {
  11. Debug bool `help:"Show debug information in log." short:"d"`
  12. Version kong.VersionFlag `help:"Show version information." short:"v"`
  13. Detect Detect `cmd:"" help:"Detect network presence and push state changes to IFTTT."`
  14. Check Check `cmd:"" help:"Check configuration."`
  15. }
  16. )
  17. var (
  18. version = "dev"
  19. commit = "none"
  20. date = "unknown"
  21. )
  22. func main() {
  23. cli := &CLI{}
  24. ctx := kong.Parse(
  25. cli,
  26. kong.Description("Home network presence detection daemon for IFTTT"), kong.UsageOnError(),
  27. kong.Vars{
  28. "version": fmt.Sprintf("presence version %v %v %v/%v %v %v", version, runtime.Version(), runtime.GOOS, runtime.GOARCH, commit, date),
  29. },
  30. )
  31. err := ctx.Run(cli)
  32. ctx.FatalIfErrorf(err)
  33. }
  34. func (cli *CLI) Context() (ctx context.Context) {
  35. ctx = context.Background()
  36. if cli.Debug {
  37. ctx = log.Context(ctx, log.WithDebug())
  38. } else {
  39. ctx = log.Context(ctx)
  40. }
  41. return
  42. }