-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconfig.go
More file actions
66 lines (53 loc) · 1.74 KB
/
config.go
File metadata and controls
66 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"log"
"os"
"gopkg.in/yaml.v3"
)
// processConfigFile parses a plugin configuration file and collects installation tasks
func processConfigFile(configFile string, verbose bool) ([]PluginInstallTask, error) {
log.Printf("Processing plugin configuration file: %s", configFile)
data, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
var config PluginConfig
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse config file: %w", err)
}
var tasks []PluginInstallTask
seenPlugins := make(map[string]bool)
// Process each plugin type
for pluginType, plugins := range config.Plugins {
for _, plugin := range plugins {
key := pluginKey(pluginType, plugin)
// Check for duplicates within this file
if seenPlugins[key] {
return nil, fmt.Errorf("duplicate plugin found: %s in file %s", key, configFile)
}
seenPlugins[key] = true
if verbose {
log.Printf("Found plugin %s, enabled: %v", key, isPluginEnabled(plugin))
}
// Add to installation tasks if enabled
if isPluginEnabled(plugin) {
tasks = append(tasks, PluginInstallTask{
PluginType: pluginType,
Plugin: plugin,
Defaults: config.Defaults,
ConfigFile: configFile,
})
}
}
}
return tasks, nil
}
// pluginKey creates a unique key for a plugin to detect duplicates
func pluginKey(pluginType string, plugin PluginDef) string {
return fmt.Sprintf("%s:%s:%s", pluginType, plugin.ModuleURI, plugin.InstallPath)
}
// isPluginEnabled checks if a plugin is enabled (defaults to true if not explicitly set to false)
func isPluginEnabled(plugin PluginDef) bool {
return plugin.Enabled == nil || *plugin.Enabled
}