main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/log"
  9. )
  10. var version = "master"
  11. func getGrafanaPluginDir() 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.Usage = ""
  24. app.Author = "Grafana Project"
  25. app.Email = "https://github.com/grafana/grafana"
  26. app.Version = version
  27. app.Flags = []cli.Flag{
  28. cli.StringFlag{
  29. Name: "pluginsDir",
  30. Usage: "path to the grafana plugin directory",
  31. Value: getGrafanaPluginDir(),
  32. EnvVar: "GF_PLUGIN_DIR",
  33. },
  34. cli.StringFlag{
  35. Name: "repo",
  36. Usage: "url to the plugin repository",
  37. Value: "https://grafana.net/api/plugins",
  38. EnvVar: "GF_PLUGIN_REPO",
  39. },
  40. cli.BoolFlag{
  41. Name: "debug, d",
  42. Usage: "enable debug logging",
  43. },
  44. }
  45. app.Commands = commands.Commands
  46. app.CommandNotFound = cmdNotFound
  47. if err := app.Run(os.Args); err != nil {
  48. log.Errorf("%v", err)
  49. }
  50. }
  51. func SetupLogging() {
  52. for _, f := range os.Args {
  53. if f == "-D" || f == "--debug" || f == "-debug" {
  54. log.SetDebug(true)
  55. }
  56. }
  57. }
  58. func cmdNotFound(c *cli.Context, command string) {
  59. fmt.Printf(
  60. "%s: '%s' is not a %s command. See '%s --help'.\n",
  61. c.App.Name,
  62. command,
  63. c.App.Name,
  64. os.Args[0],
  65. )
  66. os.Exit(1)
  67. }