diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index 131d9189022..fbdec792322 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/pkg/cmd/grafana-cli/main.go @@ -8,39 +8,11 @@ import ( "github.com/codegangsta/cli" "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" + "github.com/grafana/grafana/pkg/cmd/grafana-cli/utils" ) var version = "master" -func getGrafanaPluginDir() string { - currentOS := runtime.GOOS - defaultNix := "/var/lib/grafana/plugins" - - if currentOS == "windows" { - return "../data/plugins" - } - - pwd, err := os.Getwd() - - if err != nil { - logger.Error("Could not get current path. using default") - return defaultNix - } - - if isDevenvironment(pwd) { - return "../data/plugins" - } - - return defaultNix -} - -func isDevenvironment(pwd string) bool { - // if ../conf/defaults.ini exists, grafana is not installed as package - // that its in development environment. - _, err := os.Stat("../conf/defaults.ini") - return err == nil -} - func main() { setupLogging() @@ -54,7 +26,7 @@ func main() { cli.StringFlag{ Name: "pluginsDir", Usage: "path to the grafana plugin directory", - Value: getGrafanaPluginDir(), + Value: utils.GetGrafanaPluginDir(runtime.GOOS), EnvVar: "GF_PLUGIN_DIR", }, cli.StringFlag{ diff --git a/pkg/cmd/grafana-cli/utils/grafana_path.go b/pkg/cmd/grafana-cli/utils/grafana_path.go new file mode 100644 index 00000000000..fa6dc46d783 --- /dev/null +++ b/pkg/cmd/grafana-cli/utils/grafana_path.go @@ -0,0 +1,46 @@ +package utils + +import ( + "os" + + "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" +) + +func GetGrafanaPluginDir(currentOS string) string { + //currentOS := runtime.GOOS + + if currentOS == "windows" { + return returnOsDefault(currentOS) + } + + pwd, err := os.Getwd() + + if err != nil { + logger.Error("Could not get current path. using default") + return returnOsDefault(currentOS) + } + + if isDevenvironment(pwd) { + return "../data/plugins" + } + + return returnOsDefault(currentOS) +} + +func isDevenvironment(pwd string) bool { + // if ../conf/defaults.ini exists, grafana is not installed as package + // that its in development environment. + _, err := os.Stat("../conf/defaults.ini") + return err == nil +} + +func returnOsDefault(currentOs string) string { + switch currentOs { + case "windows": + return "../data/plugins" + case "darwin": + return "/usr/local/var/lib/grafana/plugins" + default: //"linux" + return "/var/lib/grafana/plugins" + } +}