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

85 lines
1.8 KiB
Go
Raw Normal View History

2016-02-15 14:09:34 +01:00
package main
import (
"fmt"
2016-03-28 21:42:26 +02:00
"os"
"runtime"
2016-02-15 14:09:34 +01:00
"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/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
2016-02-15 14:09:34 +01:00
)
2016-02-15 16:11:37 +01:00
var version = "master"
2016-02-15 14:09:34 +01:00
func main() {
setupLogging()
2016-02-15 14:09:34 +01:00
app := cli.NewApp()
app.Name = "Grafana cli"
2016-03-28 21:42:26 +02:00
app.Usage = ""
app.Author = "Grafana Project"
2016-02-15 14:09:34 +01:00
app.Email = "https://github.com/grafana/grafana"
2016-02-15 16:11:37 +01:00
app.Version = version
2016-02-15 14:09:34 +01:00
app.Flags = []cli.Flag{
cli.StringFlag{
2016-03-28 21:42:26 +02:00
Name: "pluginsDir",
Usage: "path to the grafana plugin directory",
Value: utils.GetGrafanaPluginDir(runtime.GOOS),
2016-03-21 10:05:23 +01:00
EnvVar: "GF_PLUGIN_DIR",
2016-02-15 14:09:34 +01:00
},
cli.StringFlag{
2016-03-21 10:05:23 +01:00
Name: "repo",
Usage: "url to the plugin repository",
Value: "https://grafana.com/api/plugins",
2016-03-21 10:05:23 +01:00
EnvVar: "GF_PLUGIN_REPO",
},
cli.StringFlag{
Name: "pluginUrl",
Usage: "Full url to the plugin zip file instead of downloading the plugin from grafana.com/api",
Value: "",
EnvVar: "GF_PLUGIN_URL",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Skip TLS verification (insecure)",
},
2016-02-15 14:09:34 +01:00
cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug logging",
},
}
app.Before = func(c *cli.Context) error {
services.Init(version, c.GlobalBool("insecure"))
return nil
}
2016-02-15 14:09:34 +01:00
app.Commands = commands.Commands
app.CommandNotFound = cmdNotFound
if err := app.Run(os.Args); err != nil {
logger.Errorf("%v", err)
2016-02-15 14:09:34 +01:00
}
}
func setupLogging() {
2016-02-15 14:09:34 +01:00
for _, f := range os.Args {
if f == "-D" || f == "--debug" || f == "-debug" {
logger.SetDebug(true)
2016-02-15 14:09:34 +01: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)
}