Beispiel #1
0
func upgradeAllCommand(c CommandLine) error {
	pluginDir := c.GlobalString("path")

	localPlugins := services.GetLocalPlugins(pluginDir)

	remotePlugins, err := services.ListAllPlugins()

	if err != nil {
		return err
	}

	pluginsToUpgrade := make([]m.InstalledPlugin, 0)

	for _, localPlugin := range localPlugins {
		for _, remotePlugin := range remotePlugins.Plugins {
			if localPlugin.Id == remotePlugin.Id {
				if ShouldUpgrade(localPlugin.Info.Version, remotePlugin) {
					pluginsToUpgrade = append(pluginsToUpgrade, localPlugin)
				}
			}
		}
	}

	for _, p := range pluginsToUpgrade {
		log.Infof("lets upgrade %v \n", p)

		services.RemoveInstalledPlugin(pluginDir, p.Id)
		InstallPlugin(p.Id, pluginDir, "")
	}

	return nil
}
Beispiel #2
0
func lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("path")
	if err := validateCommand(pluginDir); err != nil {
		return err
	}

	for _, plugin := range getPlugins(pluginDir) {
		log.Infof("plugin: %s @ %s \n", plugin.Name, plugin.Info.Version)
	}

	return nil
}
Beispiel #3
0
func installCommand(c CommandLine) error {
	pluginFolder := c.GlobalString("path")
	if err := validateInput(c, pluginFolder); err != nil {
		return err
	}

	pluginToInstall := c.Args().First()
	version := c.Args().Get(1)

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

	return InstallPlugin(pluginToInstall, pluginFolder, version)
}
Beispiel #4
0
func listremoteCommand(c CommandLine) error {
	plugin, err := services.ListAllPlugins()

	if err != nil {
		return err
	}

	for _, i := range plugin.Plugins {
		log.Infof("id: %v version:\n", i.Id)
	}

	return nil
}
Beispiel #5
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 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
}
Beispiel #6
0
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
}