mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Adding the ability to differenitate builtin plugins when listing
This commit is contained in:
@@ -42,6 +42,7 @@ type PluginPackage struct {
|
||||
Author string
|
||||
Tags []string
|
||||
Versions PluginVersions
|
||||
Builtin bool
|
||||
}
|
||||
|
||||
// PluginPackages is a list of PluginPackage instances.
|
||||
@@ -75,6 +76,9 @@ func (pp *PluginPackage) String() string {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString("Plugin: ")
|
||||
buf.WriteString(pp.Name)
|
||||
if pp.Builtin {
|
||||
buf.WriteString(" (built-in)")
|
||||
}
|
||||
buf.WriteRune('\n')
|
||||
if pp.Author != "" {
|
||||
buf.WriteString("Author: ")
|
||||
@@ -334,7 +338,7 @@ func isUnknownCoreVersion() bool {
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
func newStaticPluginVersion(name, version string, builtin bool) *PluginVersion {
|
||||
vers, err := semver.ParseTolerant(version)
|
||||
|
||||
if err != nil {
|
||||
@@ -343,7 +347,8 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
}
|
||||
}
|
||||
pl := &PluginPackage{
|
||||
Name: name,
|
||||
Name: name,
|
||||
Builtin: builtin,
|
||||
}
|
||||
pv := &PluginVersion{
|
||||
pack: pl,
|
||||
@@ -358,7 +363,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
func GetInstalledVersions(withCore bool) PluginVersions {
|
||||
result := PluginVersions{}
|
||||
if withCore {
|
||||
result = append(result, newStaticPluginVersion(CorePluginName, util.Version))
|
||||
result = append(result, newStaticPluginVersion(CorePluginName, util.Version, true))
|
||||
}
|
||||
|
||||
for _, p := range Plugins {
|
||||
@@ -366,7 +371,7 @@ func GetInstalledVersions(withCore bool) PluginVersions {
|
||||
continue
|
||||
}
|
||||
version := GetInstalledPluginVersion(p.Name)
|
||||
if pv := newStaticPluginVersion(p.Name, version); pv != nil {
|
||||
if pv := newStaticPluginVersion(p.Name, version, p.Builtin); pv != nil {
|
||||
result = append(result, pv)
|
||||
}
|
||||
}
|
||||
@@ -604,7 +609,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
||||
// if no plugins are specified, update all installed plugins.
|
||||
if len(plugins) == 0 {
|
||||
for _, p := range Plugins {
|
||||
if !p.IsLoaded() || p.Default {
|
||||
if !p.IsLoaded() || p.Builtin {
|
||||
continue
|
||||
}
|
||||
plugins = append(plugins, p.Name)
|
||||
@@ -613,7 +618,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
||||
|
||||
fmt.Fprintln(out, "Checking for plugin updates")
|
||||
microVersion := PluginVersions{
|
||||
newStaticPluginVersion(CorePluginName, util.Version),
|
||||
newStaticPluginVersion(CorePluginName, util.Version, true),
|
||||
}
|
||||
|
||||
var updates = make(PluginDependencies, 0)
|
||||
@@ -665,8 +670,8 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
||||
for _, plugin := range args {
|
||||
// check if the plugin exists.
|
||||
for _, p := range Plugins {
|
||||
if p.Name == plugin && p.Default {
|
||||
fmt.Fprintln(out, "Default plugins cannot be removed, but can be disabled via settings.")
|
||||
if p.Name == plugin && p.Builtin {
|
||||
fmt.Fprintln(out, "Built-in plugins cannot be removed, but can be disabled via settings.")
|
||||
continue
|
||||
}
|
||||
if p.Name == plugin {
|
||||
@@ -687,7 +692,11 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
||||
plugins := GetInstalledVersions(false)
|
||||
fmt.Fprintln(out, "The following plugins are currently installed:")
|
||||
for _, p := range plugins {
|
||||
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
|
||||
if p.Pack().Builtin {
|
||||
fmt.Fprintf(out, "%s (built-in)\n", p.Pack().Name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
|
||||
}
|
||||
}
|
||||
case "search":
|
||||
plugins := SearchPlugin(out, args)
|
||||
|
||||
Reference in New Issue
Block a user