main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. "github.com/grafana/grafana/pkg/cmd/grafana-cli/version"
  8. "os"
  9. "runtime"
  10. )
  11. func getGrafanaPluginPath() string {
  12. os := runtime.GOOS
  13. if os == "linux" {
  14. return "/var/lib/grafana/plugins"
  15. } else if os == "windows" {
  16. return "C:\\opt\\grafana\\plugins" // :&
  17. }
  18. return "tmp_do/" //based on your OS!
  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.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. }