Esempio n. 1
0
func pluginInstall(c *cli.Context) error {
	// Input validation
	pluginSource := c.String("source")
	if pluginSource == "" {
		log.Fatal("Missing required input: source")
	}

	pluginBinary := c.String("bin-source")
	pluginVersionTag := c.String("version")

	// Install
	if pluginVersionTag == "" {
		log.Infof("=> Installing plugin from (%s) with latest version...", pluginSource)
	} else {
		log.Infof("=> Installing plugin (%s) with version (%s)...", pluginSource, pluginVersionTag)
	}

	plugin, version, err := plugins.InstallPlugin(pluginSource, pluginBinary, pluginVersionTag)
	if err != nil {
		log.Fatalf("Failed to install plugin from (%s), error: %s", pluginSource, err)
	}

	fmt.Println()
	log.Infoln(colorstring.Greenf("Plugin (%s) with version (%s) installed ", plugin.Name, version))

	if len(plugin.Description) > 0 {
		fmt.Println()
		fmt.Println(plugin.Description)
		fmt.Println()
	}

	return nil
}
Esempio n. 2
0
func pluginInstall(c *cli.Context) {
	// Input validation
	pluginSource := c.String("source")
	if pluginSource == "" {
		log.Fatalln("Missing required input: source")
	}

	pluginName := c.String("name")
	if pluginName == "" {
		log.Fatalf("Missing required input: name")
	}

	pluginType := c.String("type")
	if pluginType == "" {
		pluginType = plugins.TypeGeneric
	}

	// Install
	log.Infof("=> Installing plugin (%s)...", plugins.PrintableName(pluginName, pluginType))
	printableName, err := plugins.InstallPlugin(c.App.Version, pluginSource, pluginName, pluginType)
	if err != nil {
		log.Fatalf("Failed to install plugin, err: %s", err)
	}
	fmt.Println()
	log.Infoln(colorstring.Greenf("Plugin (%s) installed", printableName))
}
Esempio n. 3
0
func pluginUpdate(c *cli.Context) error {
	// Input validation
	if len(c.Args()) == 0 {
		log.Fatal("Missing plugin name")
	}

	name := c.Args()[0]
	if name == "" {
		log.Fatal("Missing plugin name")
	}

	plugin, found, err := plugins.LoadPlugin(name)
	if err != nil {
		log.Fatalf("Failed to check if plugin (%s) installed, error: %s", name, err)
	} else if !found {
		log.Fatalf("Plugin (%s) is not installed", name)
	}

	// Check for new version
	if newVersion, err := plugins.CheckForNewVersion(plugin); err != nil {
		log.Fatalf("Failed to check for plugin (%s) new version, error: %s", plugin.Name, err)
	} else if newVersion != "" {
		log.Infof("Installing new version (%s) of plugin (%s)", newVersion, plugin.Name)

		route, found, err := plugins.ReadPluginRoute(plugin.Name)
		if err != nil {
			log.Fatalf("Failed to read plugin route, error: %s", err)
		}
		if !found {
			log.Fatalf("no route found for already loaded plugin (%s)", plugin.Name)
		}

		plugin, version, err := plugins.InstallPlugin(route.Source, newVersion)
		if err != nil {
			log.Fatalf("Failed to install plugin from (%s), error: %s", route.Source, err)
		}

		fmt.Println()
		log.Infoln(colorstring.Greenf("Plugin (%s) with version (%s) installed ", plugin.Name, version))

		if len(plugin.Description) > 0 {
			fmt.Println()
			fmt.Println(plugin.Description)
			fmt.Println()
		}
	} else {
		log.Info("No new version available")
	}

	return nil
}
Esempio n. 4
0
// CheckIsPluginInstalled ...
func CheckIsPluginInstalled(name string, dependency PluginDependency) error {
	_, found, err := plugins.LoadPlugin(name)
	if err != nil {
		return err
	}

	currentVersion := ""
	installOrUpdate := false

	if !found {
		fmt.Println()
		log.Warnf("Default plugin (%s) NOT found.", name)
		fmt.Println()

		fmt.Print("Installing...")
		installOrUpdate = true
		currentVersion = dependency.MinVersion
	} else {
		installedVersion, err := plugins.GetPluginVersion(name)
		if err != nil {
			return err
		}

		if installedVersion == nil {
			fmt.Println()
			log.Warnf("Default plugin (%s) is not installed from git, no version info available.", name)
			fmt.Println()

			currentVersion = "local"
		} else {
			currentVersion = installedVersion.String()

			minVersion, err := ver.NewVersion(dependency.MinVersion)
			if err != nil {
				return err
			}

			if installedVersion.LessThan(minVersion) {
				fmt.Println()
				log.Warnf("Default plugin (%s) version (%s) is lower than required (%s).", name, installedVersion.String(), minVersion.String())
				fmt.Println()

				log.Infoln("Updating...")
				installOrUpdate = true
				currentVersion = dependency.MinVersion
			}
		}
	}

	if installOrUpdate {
		var plugin plugins.Plugin
		err := progress.SimpleProgressE(".", 2*time.Second, func() error {
			return retry.Times(2).Wait(5 * time.Second).Try(func(attempt uint) error {
				if attempt > 0 {
					fmt.Println()
					fmt.Print("==> Download failed, retrying ...")
				}
				p, _, err := plugins.InstallPlugin(dependency.Source, dependency.Binary, dependency.MinVersion)
				plugin = p
				return err
			})
		})
		fmt.Println()

		if err != nil {
			return fmt.Errorf("Failed to install plugin, error: %s", err)
		}

		if len(plugin.Description) > 0 {
			fmt.Println()
			fmt.Println(plugin.Description)
			fmt.Println()
		}
	}

	pluginDir := plugins.GetPluginDir(name)

	log.Infof(" * %s Plugin (%s) : %s", colorstring.Green("[OK]"), name, pluginDir)
	log.Infof("        version : %s", currentVersion)

	return nil
}