mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 14:10:23 +09:00
Merge pull request #3810 from Neko-Box-Coder/ShowBuiltinPlugins
Adding the ability to differentiate builtin plugins when listing
This commit is contained in:
@@ -71,7 +71,7 @@ type Plugin struct {
|
|||||||
Info *PluginInfo // json file containing info
|
Info *PluginInfo // json file containing info
|
||||||
Srcs []RuntimeFile // lua files
|
Srcs []RuntimeFile // lua files
|
||||||
Loaded bool
|
Loaded bool
|
||||||
Default bool // pre-installed plugin
|
Builtin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLoaded returns if a plugin is enabled
|
// IsLoaded returns if a plugin is enabled
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ type PluginPackage struct {
|
|||||||
Author string
|
Author string
|
||||||
Tags []string
|
Tags []string
|
||||||
Versions PluginVersions
|
Versions PluginVersions
|
||||||
|
Builtin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginPackages is a list of PluginPackage instances.
|
// PluginPackages is a list of PluginPackage instances.
|
||||||
@@ -75,6 +76,9 @@ func (pp *PluginPackage) String() string {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.WriteString("Plugin: ")
|
buf.WriteString("Plugin: ")
|
||||||
buf.WriteString(pp.Name)
|
buf.WriteString(pp.Name)
|
||||||
|
if pp.Builtin {
|
||||||
|
buf.WriteString(" (built-in)")
|
||||||
|
}
|
||||||
buf.WriteRune('\n')
|
buf.WriteRune('\n')
|
||||||
if pp.Author != "" {
|
if pp.Author != "" {
|
||||||
buf.WriteString("Author: ")
|
buf.WriteString("Author: ")
|
||||||
@@ -334,7 +338,7 @@ func isUnknownCoreVersion() bool {
|
|||||||
return err != nil
|
return err != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStaticPluginVersion(name, version string) *PluginVersion {
|
func newStaticPluginVersion(name, version string, builtin bool) *PluginVersion {
|
||||||
vers, err := semver.ParseTolerant(version)
|
vers, err := semver.ParseTolerant(version)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -344,6 +348,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
|||||||
}
|
}
|
||||||
pl := &PluginPackage{
|
pl := &PluginPackage{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
Builtin: builtin,
|
||||||
}
|
}
|
||||||
pv := &PluginVersion{
|
pv := &PluginVersion{
|
||||||
pack: pl,
|
pack: pl,
|
||||||
@@ -358,7 +363,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
|||||||
func GetInstalledVersions(withCore bool) PluginVersions {
|
func GetInstalledVersions(withCore bool) PluginVersions {
|
||||||
result := PluginVersions{}
|
result := PluginVersions{}
|
||||||
if withCore {
|
if withCore {
|
||||||
result = append(result, newStaticPluginVersion(CorePluginName, util.Version))
|
result = append(result, newStaticPluginVersion(CorePluginName, util.Version, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range Plugins {
|
for _, p := range Plugins {
|
||||||
@@ -366,7 +371,7 @@ func GetInstalledVersions(withCore bool) PluginVersions {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
version := GetInstalledPluginVersion(p.Name)
|
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)
|
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 no plugins are specified, update all installed plugins.
|
||||||
if len(plugins) == 0 {
|
if len(plugins) == 0 {
|
||||||
for _, p := range Plugins {
|
for _, p := range Plugins {
|
||||||
if !p.IsLoaded() || p.Default {
|
if !p.IsLoaded() || p.Builtin || p.Name == "initlua" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
plugins = append(plugins, p.Name)
|
plugins = append(plugins, p.Name)
|
||||||
@@ -613,7 +618,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
|||||||
|
|
||||||
fmt.Fprintln(out, "Checking for plugin updates")
|
fmt.Fprintln(out, "Checking for plugin updates")
|
||||||
microVersion := PluginVersions{
|
microVersion := PluginVersions{
|
||||||
newStaticPluginVersion(CorePluginName, util.Version),
|
newStaticPluginVersion(CorePluginName, util.Version, true),
|
||||||
}
|
}
|
||||||
|
|
||||||
var updates = make(PluginDependencies, 0)
|
var updates = make(PluginDependencies, 0)
|
||||||
@@ -663,10 +668,14 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
|||||||
case "remove":
|
case "remove":
|
||||||
removed := ""
|
removed := ""
|
||||||
for _, plugin := range args {
|
for _, plugin := range args {
|
||||||
|
if plugin == "initlua" {
|
||||||
|
fmt.Fprintln(out, "initlua cannot be removed, but can be disabled via settings.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
// check if the plugin exists.
|
// check if the plugin exists.
|
||||||
for _, p := range Plugins {
|
for _, p := range Plugins {
|
||||||
if p.Name == plugin && p.Default {
|
if p.Name == plugin && p.Builtin {
|
||||||
fmt.Fprintln(out, "Default plugins cannot be removed, but can be disabled via settings.")
|
fmt.Fprintln(out, p.Name, "is a built-in plugin which cannot be removed, but can be disabled via settings.")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p.Name == plugin {
|
if p.Name == plugin {
|
||||||
@@ -687,8 +696,14 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
|||||||
plugins := GetInstalledVersions(false)
|
plugins := GetInstalledVersions(false)
|
||||||
fmt.Fprintln(out, "The following plugins are currently installed:")
|
fmt.Fprintln(out, "The following plugins are currently installed:")
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
|
if p.Pack().Name == "initlua" {
|
||||||
|
fmt.Fprintf(out, "%s\n", "initlua")
|
||||||
|
} else 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)
|
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case "search":
|
case "search":
|
||||||
plugins := SearchPlugin(out, args)
|
plugins := SearchPlugin(out, args)
|
||||||
fmt.Fprintln(out, len(plugins), " plugins found")
|
fmt.Fprintln(out, len(plugins), " plugins found")
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ func InitPlugins() {
|
|||||||
p.Name = "initlua"
|
p.Name = "initlua"
|
||||||
p.DirName = "initlua"
|
p.DirName = "initlua"
|
||||||
p.Srcs = append(p.Srcs, realFile(initlua))
|
p.Srcs = append(p.Srcs, realFile(initlua))
|
||||||
|
p.Builtin = false
|
||||||
Plugins = append(Plugins, p)
|
Plugins = append(Plugins, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ func InitPlugins() {
|
|||||||
p := new(Plugin)
|
p := new(Plugin)
|
||||||
p.Name = d
|
p.Name = d
|
||||||
p.DirName = d
|
p.DirName = d
|
||||||
p.Default = true
|
p.Builtin = true
|
||||||
for _, f := range srcs {
|
for _, f := range srcs {
|
||||||
if strings.HasSuffix(f, ".lua") {
|
if strings.HasSuffix(f, ".lua") {
|
||||||
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
||||||
|
|||||||
Reference in New Issue
Block a user