main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. cli.StringFlag{
  49. Name: "configOverrides",
  50. Usage: "configuration options to override defaults as a string. e.g. cfg:default.paths.log=/dev/null",
  51. },
  52. cli.StringFlag{
  53. Name: "homepath",
  54. Usage: "path to grafana install/home path, defaults to working directory",
  55. },
  56. cli.StringFlag{
  57. Name: "config",
  58. Usage: "path to config file",
  59. },
  60. }
  61. app.Before = func(c *cli.Context) error {
  62. services.Init(version, c.GlobalBool("insecure"))
  63. return nil
  64. }
  65. app.Commands = commands.Commands
  66. app.CommandNotFound = cmdNotFound
  67. if err := app.Run(os.Args); err != nil {
  68. logger.Errorf("%v", err)
  69. }
  70. }
  71. func setupLogging() {
  72. for _, f := range os.Args {
  73. if f == "-d" || f == "--debug" || f == "-debug" {
  74. logger.SetDebug(true)
  75. }
  76. }
  77. }
  78. func cmdNotFound(c *cli.Context, command string) {
  79. fmt.Printf(
  80. "%s: '%s' is not a %s command. See '%s --help'.\n",
  81. c.App.Name,
  82. command,
  83. c.App.Name,
  84. os.Args[0],
  85. )
  86. os.Exit(1)
  87. }