main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if os.Getenv("GF_PLUGIN_DIR") != "" {
  13. return os.Getenv("GF_PLUGIN_DIR")
  14. }
  15. os := runtime.GOOS
  16. if os == "windows" {
  17. return "C:\\opt\\grafana\\plugins"
  18. } else {
  19. return "/var/lib/grafana/plugins"
  20. }
  21. }
  22. func main() {
  23. SetupLogging()
  24. app := cli.NewApp()
  25. app.Name = "Grafana cli"
  26. app.Author = "raintank"
  27. app.Email = "https://github.com/grafana/grafana"
  28. app.Version = version
  29. app.Flags = []cli.Flag{
  30. cli.StringFlag{
  31. Name: "path",
  32. Usage: "path to the grafana installation",
  33. Value: getGrafanaPluginPath(),
  34. },
  35. cli.StringFlag{
  36. Name: "repo",
  37. Usage: "url to the plugin repository",
  38. Value: "",
  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. }