main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //TODO: try to get path from os:env GF_PLUGIN_FOLDER
  13. os := runtime.GOOS
  14. if os == "windows" {
  15. return "C:\\opt\\grafana\\plugins"
  16. } else {
  17. return "/var/lib/grafana/plugins"
  18. }
  19. }
  20. func main() {
  21. SetupLogging()
  22. app := cli.NewApp()
  23. app.Name = "Grafana cli"
  24. app.Author = "raintank"
  25. app.Email = "https://github.com/grafana/grafana"
  26. app.Version = version
  27. app.Flags = []cli.Flag{
  28. cli.StringFlag{
  29. Name: "path",
  30. Usage: "path to the grafana installation",
  31. Value: getGrafanaPluginPath(),
  32. },
  33. cli.BoolFlag{
  34. Name: "debug, d",
  35. Usage: "enable debug logging",
  36. },
  37. }
  38. app.Commands = commands.Commands
  39. app.CommandNotFound = cmdNotFound
  40. if err := app.Run(os.Args); err != nil {
  41. log.Errorf("%v", err)
  42. }
  43. }
  44. func SetupLogging() {
  45. for _, f := range os.Args {
  46. if f == "-D" || f == "--debug" || f == "-debug" {
  47. log.SetDebug(true)
  48. }
  49. }
  50. }
  51. func cmdNotFound(c *cli.Context, command string) {
  52. fmt.Printf(
  53. "%s: '%s' is not a %s command. See '%s --help'.\n",
  54. c.App.Name,
  55. command,
  56. c.App.Name,
  57. os.Args[0],
  58. )
  59. os.Exit(1)
  60. }