new command plugin list

this command shows all currently installed plugins and their verion
This commit is contained in:
boombuler
2016-10-01 07:37:20 +02:00
parent 8ad2179423
commit b54853140a
3 changed files with 22 additions and 7 deletions

View File

@@ -151,7 +151,7 @@ func PluginComplete(complete Completion, input string) (chosen string, suggestio
}
func PluginCmdComplete(input string) (chosen string, suggestions []string) {
for _, cmd := range []string{"install", "remove", "search", "update"} {
for _, cmd := range []string{"install", "remove", "search", "update", "list"} {
if strings.HasPrefix(cmd, input) {
suggestions = append(suggestions, cmd)
}

View File

@@ -2,6 +2,7 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
@@ -118,6 +119,19 @@ func PluginCmd(args []string) {
}
case "update":
UpdatePlugins(args[1:])
case "list":
plugins := GetInstalledVersions(false)
messenger.AddLog("----------------")
messenger.AddLog("The following plugins are currently installed:\n")
for _, p := range plugins {
messenger.AddLog(fmt.Sprintf("%s (%s)", p.pack.Name, p.Version))
}
messenger.AddLog("----------------")
if len(plugins) > 0 {
if CurView().Type != vtLog {
ToggleLog([]string{})
}
}
case "search":
plugins := SearchPlugin(args[1:])
messenger.Message(len(plugins), " plugins found")

View File

@@ -261,7 +261,7 @@ func (pp PluginPackage) Match(text string) bool {
// IsInstallable returns true if the package can be installed.
func (pp PluginPackage) IsInstallable() bool {
_, err := GetAllPluginPackages().Resolve(GetInstalledVersions(), PluginDependencies{
_, err := GetAllPluginPackages().Resolve(GetInstalledVersions(true), PluginDependencies{
&PluginDependency{
Name: pp.Name,
Range: semver.Range(func(v semver.Version) bool { return true }),
@@ -310,9 +310,10 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
// GetInstalledVersions returns a list of all currently installed plugins including an entry for
// micro itself. This can be used to resolve dependencies.
func GetInstalledVersions() PluginVersions {
result := PluginVersions{
newStaticPluginVersion(CorePluginName, Version),
func GetInstalledVersions(withCore bool) PluginVersions {
result := PluginVersions{}
if withCore {
result = append(result, newStaticPluginVersion(CorePluginName, Version))
}
for _, name := range loadedPlugins {
@@ -460,7 +461,7 @@ func (all PluginPackages) Resolve(selectedVersions PluginVersions, open PluginDe
func (versions PluginVersions) install() {
anyInstalled := false
currentlyInstalled := GetInstalledVersions()
currentlyInstalled := GetInstalledVersions(true)
for _, sel := range versions {
if sel.pack.Name != CorePluginName {
@@ -498,7 +499,7 @@ func UninstallPlugin(name string) {
}
func (pl PluginPackage) Install() {
selected, err := GetAllPluginPackages().Resolve(GetInstalledVersions(), PluginDependencies{
selected, err := GetAllPluginPackages().Resolve(GetInstalledVersions(true), PluginDependencies{
&PluginDependency{
Name: pl.Name,
Range: semver.Range(func(v semver.Version) bool { return true }),