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"
|
2016-06-03 12:19:04 +02:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
2016-09-15 16:01:06 +02:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
2016-08-15 08:54:35 +02:00
|
|
|
"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() {
|
2016-06-03 12:19:04 +02:00
|
|
|
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",
|
2016-08-15 08:54:35 +02:00
|
|
|
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
|
|
|
},
|
2016-03-07 13:27:51 +01:00
|
|
|
cli.StringFlag{
|
2016-03-21 10:05:23 +01:00
|
|
|
Name: "repo",
|
|
|
|
|
Usage: "url to the plugin repository",
|
2017-03-20 10:20:32 +01:00
|
|
|
Value: "https://grafana.com/api/plugins",
|
2016-03-21 10:05:23 +01:00
|
|
|
EnvVar: "GF_PLUGIN_REPO",
|
2016-03-07 13:27:51 +01:00
|
|
|
},
|
2017-09-15 20:34:08 +02:00
|
|
|
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",
|
|
|
|
|
},
|
2017-09-28 11:10:59 +01:00
|
|
|
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",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:10:59 +01:00
|
|
|
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 {
|
2016-06-03 12:19:04 +02:00
|
|
|
logger.Errorf("%v", err)
|
2016-02-15 14:09:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 12:19:04 +02:00
|
|
|
func setupLogging() {
|
2016-02-15 14:09:34 +01:00
|
|
|
for _, f := range os.Args {
|
|
|
|
|
if f == "-D" || f == "--debug" || f == "-debug" {
|
2016-06-03 12:19:04 +02:00
|
|
|
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)
|
|
|
|
|
}
|