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") } } }
func removeCommand(c CommandLine) error { pluginPath := c.GlobalString("path") localPlugins := getPluginss(pluginPath) log.Info("remove!\n") plugin := c.Args().First() log.Info("plugin: " + plugin + "\n") if plugin == "" { return errors.New("Missing which plugin parameter") } log.Infof("plugins : \n%v\n", localPlugins) for _, p := range localPlugins { log.Infof("is %s == %s ? %v", p.Id, c.Args().First(), p.Id == c.Args().First()) if p.Id == c.Args().First() { removePlugin(pluginPath, p.Id) } } return nil }
func validateCommand(pluginDir string) error { if pluginDir == "" { return errors.New("missing path flag") } log.Info("plugindir: " + pluginDir + "\n") pluginDirInfo, err := GetStat.Stat(pluginDir) if err != nil { return errors.New("missing path flag") } if pluginDirInfo.IsDir() == false { return errors.New("plugin path is not a directory") } return nil }
func InstallPlugin(pluginName, pluginFolder, version string) error { plugin, err := services.GetPlugin(pluginName) if err != nil { return err } v, err := SelectVersion(plugin, version) if err != nil { return err } url := v.Url commit := v.Commit downloadURL := url + "/archive/" + commit + ".zip" log.Infof("installing %v @ %v\n", plugin.Id, version) log.Infof("from url: %v\n", downloadURL) log.Infof("on commit: %v\n", commit) log.Infof("into: %v\n", pluginFolder) err = downloadFile(plugin.Id, pluginFolder, downloadURL) if err == nil { log.Info("Installed %s successfully ✔\n", plugin.Id) } res := services.ReadPlugin(pluginFolder, pluginName) for _, v := range res.Dependency.Plugins { log.Infof("Depends on %s install!\n", v.Id) //Todo: uncomment this code once the repo is more correct. //InstallPlugin(v.Id, pluginFolder, "") } return err }