func main() { SetupLogging() app := cli.NewApp() app.Name = "Grafana cli" app.Author = "raintank" app.Email = "https://github.com/grafana/grafana" app.Version = version.Version app.Flags = []cli.Flag{ cli.StringFlag{ Name: "path", Usage: "path to the grafana installation", Value: getGrafanaPluginPath(), }, 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 downloadFile(pluginName, filepath, url string) (err error) { resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } r, err := zip.NewReader(bytes.NewReader(body), resp.ContentLength) if err != nil { return err } for _, zf := range r.File { newfile := path.Join(filepath, RemoveGitBuildFromname(pluginName, zf.Name)) if zf.FileInfo().IsDir() { os.Mkdir(newfile, 0777) } else { dst, err := os.Create(newfile) if err != nil { log.Errorf("%v", err) } defer dst.Close() src, err := zf.Open() if err != nil { log.Errorf("%v", err) } defer src.Close() io.Copy(dst, src) } } return nil }
func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) { return func(context *cli.Context) { cmd := &contextCommandLine{context} if err := command(cmd); err != nil { log.Errorf("%v\n\n", err) cmd.ShowHelp() } else { log.Info("Restart grafana after installing plugins . <service grafana-server restart>\n") } } }