mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 14:22:42 +09:00
allow user to set plugin channels / repos in settings.json
This commit is contained in:
@@ -19,10 +19,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
pluginChannels PluginChannels = PluginChannels{
|
||||
PluginChannel("https://www.boombuler.de/channel.json"),
|
||||
}
|
||||
|
||||
allPluginPackages PluginPackages = nil
|
||||
)
|
||||
|
||||
@@ -211,7 +207,40 @@ func (pp *PluginPackage) UnmarshalJSON(data []byte) error {
|
||||
// GetAllPluginPackages gets all PluginPackages which may be available.
|
||||
func GetAllPluginPackages() PluginPackages {
|
||||
if allPluginPackages == nil {
|
||||
allPluginPackages = pluginChannels.Fetch()
|
||||
getOption := func(name string) []string {
|
||||
data := GetOption(name)
|
||||
if strs, ok := data.([]string); ok {
|
||||
return strs
|
||||
}
|
||||
if ifs, ok := data.([]interface{}); ok {
|
||||
result := make([]string, len(ifs))
|
||||
for i, urlIf := range ifs {
|
||||
if url, ok := urlIf.(string); ok {
|
||||
result[i] = url
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
channels := PluginChannels{}
|
||||
for _, url := range getOption("pluginchannels") {
|
||||
channels = append(channels, PluginChannel(url))
|
||||
}
|
||||
repos := []PluginRepository{}
|
||||
for _, url := range getOption("pluginrepos") {
|
||||
repos = append(repos, PluginRepository(url))
|
||||
}
|
||||
allPluginPackages = fetchAllSources(len(repos)+1, func(i int) PluginPackages {
|
||||
if i == 0 {
|
||||
return channels.Fetch()
|
||||
} else {
|
||||
return repos[i-1].Fetch()
|
||||
}
|
||||
})
|
||||
}
|
||||
return allPluginPackages
|
||||
}
|
||||
|
||||
@@ -192,6 +192,10 @@ func DefaultGlobalSettings() map[string]interface{} {
|
||||
"syntax": true,
|
||||
"tabsize": float64(4),
|
||||
"tabstospaces": false,
|
||||
"pluginchannels": []string{
|
||||
"https://www.boombuler.de/channel.json",
|
||||
},
|
||||
"pluginrepos": []string{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user