main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "github.com/slackhq/nebula"
  7. )
  8. // A version string that can be set with
  9. //
  10. // -ldflags "-X main.Build=SOMEVERSION"
  11. //
  12. // at compile-time.
  13. var Build string
  14. func main() {
  15. serviceFlag := flag.String("service", "", "Control the system service.")
  16. configPath := flag.String("config", "", "Path to either a file or directory to load configuration from")
  17. configTest := flag.Bool("test", false, "Test the config and print the end result. Non zero exit indicates a faulty config")
  18. printVersion := flag.Bool("version", false, "Print version")
  19. printUsage := flag.Bool("help", false, "Print command line usage")
  20. flag.Parse()
  21. if *printVersion {
  22. fmt.Printf("Version: %s\n", Build)
  23. os.Exit(0)
  24. }
  25. if *printUsage {
  26. flag.Usage()
  27. os.Exit(0)
  28. }
  29. if *serviceFlag != "" {
  30. doService(configPath, configTest, Build, serviceFlag)
  31. os.Exit(1)
  32. }
  33. if *configPath == "" {
  34. fmt.Println("-config flag must be set")
  35. flag.Usage()
  36. os.Exit(1)
  37. }
  38. nebula.Main(*configPath, *configTest, Build)
  39. }