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

	localPlugins := s.GetLocalPlugins(pluginDir)

	remotePlugins, err := s.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("Upgrading %v \n", p.Id)

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

	return nil
}
示例#2
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
}
示例#3
0
func lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("path")
	if err := validateLsCommmand(pluginDir); err != nil {
		return err
	}

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

	return nil
}
示例#4
0
func InstallPlugin(pluginName, pluginFolder, version string) error {
	plugin, err := s.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.Infof("Installed %v successfully ✔\n", plugin.Id)
	}

	res, _ := s.ReadPlugin(pluginFolder, pluginName)

	for _, v := range res.Dependency.Plugins {
		InstallPlugin(v.Id, pluginFolder, "")
		log.Infof("Installed Dependency: %v ✔\n", v.Id)
	}

	return err
}
示例#5
0
func listremoteCommand(c CommandLine) error {
	plugin, err := s.ListAllPlugins()

	if err != nil {
		return err
	}

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

	return nil
}
示例#6
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)
}
示例#7
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
}
示例#8
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
}
示例#9
0
func listremoteCommand(c CommandLine) error {
	plugin, err := s.ListAllPlugins(c.GlobalString("repo"))

	if err != nil {
		return err
	}

	for _, i := range plugin.Plugins {
		pluginVersion := ""
		if len(i.Versions) > 0 {
			pluginVersion = i.Versions[0].Version
		}

		log.Infof("id: %v version: %s\n", i.Id, pluginVersion)
	}

	return nil
}
示例#10
0
func upgradeCommand(c CommandLine) error {
	pluginsDir := c.GlobalString("pluginsDir")
	pluginName := c.Args().First()

	localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)

	if err != nil {
		return err
	}

	v, err2 := s.GetPlugin(localPlugin.Id, c.GlobalString("repo"))

	if err2 != nil {
		return err2
	}

	if ShouldUpgrade(localPlugin.Info.Version, v) {
		s.RemoveInstalledPlugin(pluginsDir, pluginName)
		return InstallPlugin(localPlugin.Id, "", c)
	}

	log.Infof("%s %s is up to date \n", color.GreenString("✔"), localPlugin.Id)
	return nil
}
示例#11
0
func RemoveInstalledPlugin(pluginPath, id string) error {
	log.Infof("Removing plugin: %v\n", id)
	return IoHelper.RemoveAll(path.Join(pluginPath, id))
}