main.go 1.4 KB

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