Beispiel #1
0
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 plugin parameter")
	}

	log.Infof("plugins : \n%v\n", localPlugins)

	for _, p := range localPlugins {
		if p.Id == c.Args().First() {
			log.Infof("removing plugin %s", p.Id)
			removePlugin(pluginPath, p.Id)
		}
	}

	return nil
}
Beispiel #2
0
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()
			os.Exit(1)
		} else {
			log.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n")
		}
	}
}
Beispiel #3
0
func lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("pluginsDir")
	if err := validateLsCommand(pluginDir); err != nil {
		return err
	}

	plugins := ls_getPlugins(pluginDir)

	if len(plugins) > 0 {
		log.Info("installed plugins:\n")
	}

	for _, plugin := range plugins {
		log.Infof("%s %s %s \n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
	}

	return nil
}
Beispiel #4
0
func InstallPlugin(pluginName, version string, c CommandLine) error {
	plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
	pluginFolder := c.GlobalString("pluginsDir")
	if err != nil {
		return err
	}

	v, err := SelectVersion(plugin, version)
	if err != nil {
		return err
	}

	if version == "" {
		version = v.Version
	}

	downloadURL := fmt.Sprintf("%s/%s/versions/%s/download",
		c.GlobalString("repo"),
		pluginName,
		version)

	log.Infof("installing %v @ %v\n", plugin.Id, version)
	log.Infof("from url: %v\n", downloadURL)
	log.Infof("into: %v\n", pluginFolder)
	log.Info("\n")

	err = downloadFile(plugin.Id, pluginFolder, downloadURL)
	if err != nil {
		return err
	}

	log.Infof("%s Installed %s successfully \n", color.GreenString("✔"), plugin.Id)

	/* Enable once we need support for downloading depedencies
	res, _ := s.ReadPlugin(pluginFolder, pluginName)
	for _, v := range res.Dependency.Plugins {
		InstallPlugin(v.Id, version, c)
		log.Infof("Installed dependency: %v ✔\n", v.Id)
	}
	*/
	return err
}
Beispiel #5
0
import (
	"errors"
	"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
	m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
	s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
)

var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins

var validateLsCommmand = func(pluginDir string) error {
	if pluginDir == "" {
		return errors.New("missing path flag")
	}

	log.Info("plugindir: " + pluginDir + "\n")
	pluginDirInfo, err := s.IoHelper.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 lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("path")