main.go 1.8 KB

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