2016-02-15 07:09:34 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-03-28 14:42:26 -05:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
2016-02-15 07:09:34 -06:00
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
|
2016-06-03 05:19:04 -05:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
2016-02-15 07:09:34 -06:00
|
|
|
)
|
|
|
|
|
2016-02-15 09:11:37 -06:00
|
|
|
var version = "master"
|
|
|
|
|
2016-03-28 14:42:26 -05:00
|
|
|
func getGrafanaPluginDir() string {
|
2016-04-08 04:59:45 -05:00
|
|
|
currentOS := runtime.GOOS
|
|
|
|
defaultNix := "/var/lib/grafana/plugins"
|
|
|
|
|
|
|
|
if currentOS == "windows" {
|
2016-04-19 01:27:26 -05:00
|
|
|
return "../data/plugins"
|
2016-02-15 07:09:34 -06:00
|
|
|
}
|
2016-04-08 04:59:45 -05:00
|
|
|
|
|
|
|
pwd, err := os.Getwd()
|
|
|
|
|
|
|
|
if err != nil {
|
2016-06-03 06:40:48 -05:00
|
|
|
logger.Error("Could not get current path. using default")
|
2016-04-08 04:59:45 -05:00
|
|
|
return defaultNix
|
|
|
|
}
|
|
|
|
|
|
|
|
if isDevenvironment(pwd) {
|
2016-04-19 01:27:26 -05:00
|
|
|
return "../data/plugins"
|
2016-04-08 04:59:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return defaultNix
|
|
|
|
}
|
|
|
|
|
|
|
|
func isDevenvironment(pwd string) bool {
|
2016-04-19 01:27:26 -05:00
|
|
|
// if ../conf/defaults.ini exists, grafana is not installed as package
|
2016-04-15 08:01:27 -05:00
|
|
|
// that its in development environment.
|
2016-04-19 01:27:26 -05:00
|
|
|
_, err := os.Stat("../conf/defaults.ini")
|
|
|
|
return err == nil
|
2016-02-15 07:09:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2016-06-03 05:19:04 -05:00
|
|
|
setupLogging()
|
2016-02-15 07:09:34 -06:00
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "Grafana cli"
|
2016-03-28 14:42:26 -05:00
|
|
|
app.Usage = ""
|
|
|
|
app.Author = "Grafana Project"
|
2016-02-15 07:09:34 -06:00
|
|
|
app.Email = "https://github.com/grafana/grafana"
|
2016-02-15 09:11:37 -06:00
|
|
|
app.Version = version
|
2016-02-15 07:09:34 -06:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2016-03-28 14:42:26 -05:00
|
|
|
Name: "pluginsDir",
|
|
|
|
Usage: "path to the grafana plugin directory",
|
|
|
|
Value: getGrafanaPluginDir(),
|
2016-03-21 04:05:23 -05:00
|
|
|
EnvVar: "GF_PLUGIN_DIR",
|
2016-02-15 07:09:34 -06:00
|
|
|
},
|
2016-03-07 06:27:51 -06:00
|
|
|
cli.StringFlag{
|
2016-03-21 04:05:23 -05:00
|
|
|
Name: "repo",
|
|
|
|
Usage: "url to the plugin repository",
|
2016-03-28 10:36:27 -05:00
|
|
|
Value: "https://grafana.net/api/plugins",
|
2016-03-21 04:05:23 -05:00
|
|
|
EnvVar: "GF_PLUGIN_REPO",
|
2016-03-07 06:27:51 -06:00
|
|
|
},
|
2016-02-15 07:09:34 -06:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug, d",
|
|
|
|
Usage: "enable debug logging",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = commands.Commands
|
|
|
|
app.CommandNotFound = cmdNotFound
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2016-06-03 05:19:04 -05:00
|
|
|
logger.Errorf("%v", err)
|
2016-02-15 07:09:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-03 05:19:04 -05:00
|
|
|
func setupLogging() {
|
2016-02-15 07:09:34 -06:00
|
|
|
for _, f := range os.Args {
|
|
|
|
if f == "-D" || f == "--debug" || f == "-debug" {
|
2016-06-03 05:19:04 -05:00
|
|
|
logger.SetDebug(true)
|
2016-02-15 07:09:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cmdNotFound(c *cli.Context, command string) {
|
|
|
|
fmt.Printf(
|
|
|
|
"%s: '%s' is not a %s command. See '%s --help'.\n",
|
|
|
|
c.App.Name,
|
|
|
|
command,
|
|
|
|
c.App.Name,
|
|
|
|
os.Args[0],
|
|
|
|
)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|