Skip to content

Commit 2b2e015

Browse files
committed
feat(cli): add default plugin folder for MAC OS
closes grafana#5806
1 parent 58df60f commit 2b2e015

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

pkg/cmd/grafana-cli/main.go

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,11 @@ import (
88
"github.com/codegangsta/cli"
99
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
1010
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
11+
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
1112
)
1213

1314
var version = "master"
1415

15-
func getGrafanaPluginDir() string {
16-
currentOS := runtime.GOOS
17-
defaultNix := "/var/lib/grafana/plugins"
18-
19-
if currentOS == "windows" {
20-
return "../data/plugins"
21-
}
22-
23-
pwd, err := os.Getwd()
24-
25-
if err != nil {
26-
logger.Error("Could not get current path. using default")
27-
return defaultNix
28-
}
29-
30-
if isDevenvironment(pwd) {
31-
return "../data/plugins"
32-
}
33-
34-
return defaultNix
35-
}
36-
37-
func isDevenvironment(pwd string) bool {
38-
// if ../conf/defaults.ini exists, grafana is not installed as package
39-
// that its in development environment.
40-
_, err := os.Stat("../conf/defaults.ini")
41-
return err == nil
42-
}
43-
4416
func main() {
4517
setupLogging()
4618

@@ -54,7 +26,7 @@ func main() {
5426
cli.StringFlag{
5527
Name: "pluginsDir",
5628
Usage: "path to the grafana plugin directory",
57-
Value: getGrafanaPluginDir(),
29+
Value: utils.GetGrafanaPluginDir(runtime.GOOS),
5830
EnvVar: "GF_PLUGIN_DIR",
5931
},
6032
cli.StringFlag{
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package utils
2+
3+
import (
4+
"os"
5+
6+
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
7+
)
8+
9+
func GetGrafanaPluginDir(currentOS string) string {
10+
//currentOS := runtime.GOOS
11+
12+
if currentOS == "windows" {
13+
return returnOsDefault(currentOS)
14+
}
15+
16+
pwd, err := os.Getwd()
17+
18+
if err != nil {
19+
logger.Error("Could not get current path. using default")
20+
return returnOsDefault(currentOS)
21+
}
22+
23+
if isDevenvironment(pwd) {
24+
return "../data/plugins"
25+
}
26+
27+
return returnOsDefault(currentOS)
28+
}
29+
30+
func isDevenvironment(pwd string) bool {
31+
// if ../conf/defaults.ini exists, grafana is not installed as package
32+
// that its in development environment.
33+
_, err := os.Stat("../conf/defaults.ini")
34+
return err == nil
35+
}
36+
37+
func returnOsDefault(currentOs string) string {
38+
switch currentOs {
39+
case "windows":
40+
return "../data/plugins"
41+
case "darwin":
42+
return "/usr/local/var/lib/grafana/plugins"
43+
default: //"linux"
44+
return "/var/lib/grafana/plugins"
45+
}
46+
}

0 commit comments

Comments
 (0)