main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "runtime"
  6. "github.com/codegangsta/cli"
  7. "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
  8. "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
  9. "github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
  10. )
  11. var version = "master"
  12. func main() {
  13. setupLogging()
  14. app := cli.NewApp()
  15. app.Name = "Grafana cli"
  16. app.Usage = ""
  17. app.Author = "Grafana Project"
  18. app.Email = "https://github.com/grafana/grafana"
  19. app.Version = version
  20. app.Flags = []cli.Flag{
  21. cli.StringFlag{
  22. Name: "pluginsDir",
  23. Usage: "path to the grafana plugin directory",
  24. Value: utils.GetGrafanaPluginDir(runtime.GOOS),
  25. EnvVar: "GF_PLUGIN_DIR",
  26. },
  27. cli.StringFlag{
  28. Name: "repo",
  29. Usage: "url to the plugin repository",
  30. Value: "https://grafana.net/api/plugins",
  31. EnvVar: "GF_PLUGIN_REPO",
  32. },
  33. cli.BoolFlag{
  34. Name: "debug, d",
  35. Usage: "enable debug logging",
  36. },
  37. }
  38. app.Commands = commands.Commands
  39. app.CommandNotFound = cmdNotFound
  40. if err := app.Run(os.Args); err != nil {
  41. logger.Errorf("%v", err)
  42. }
  43. }
  44. func setupLogging() {
  45. for _, f := range os.Args {
  46. if f == "-D" || f == "--debug" || f == "-debug" {
  47. logger.SetDebug(true)
  48. }
  49. }
  50. }
  51. func cmdNotFound(c *cli.Context, command string) {
  52. fmt.Printf(
  53. "%s: '%s' is not a %s command. See '%s --help'.\n",
  54. c.App.Name,
  55. command,
  56. c.App.Name,
  57. os.Args[0],
  58. )
  59. os.Exit(1)
  60. }