main.go 1.6 KB

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