grafana/pkg/cmd/grafana-cli/main.go

76 lines
1.4 KiB
Go
Raw Normal View History

2016-02-15 07:09:34 -06:00
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
"os"
"runtime"
)
2016-02-15 09:11:37 -06:00
var version = "master"
2016-02-15 07:09:34 -06:00
func getGrafanaPluginPath() string {
os := runtime.GOOS
2016-02-15 07:19:59 -06:00
if os == "windows" {
return "C:\\opt\\grafana\\plugins"
} else {
2016-02-15 07:09:34 -06:00
return "/var/lib/grafana/plugins"
}
}
func main() {
SetupLogging()
app := cli.NewApp()
app.Name = "Grafana cli"
app.Author = "raintank"
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-21 04:05:23 -05:00
Name: "path",
Usage: "path to the grafana installation",
Value: getGrafanaPluginPath(),
EnvVar: "GF_PLUGIN_DIR",
2016-02-15 07:09:34 -06:00
},
cli.StringFlag{
2016-03-21 04:05:23 -05:00
Name: "repo",
Usage: "url to the plugin repository",
Value: "https://grafana-net.raintank.io/api/plugins",
EnvVar: "GF_PLUGIN_REPO",
},
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 {
log.Errorf("%v", err)
}
}
func SetupLogging() {
for _, f := range os.Args {
if f == "-D" || f == "--debug" || f == "-debug" {
log.SetDebug(true)
}
}
}
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)
}