Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ func loadConfig(cfg *Config) error {
}
defaultConfigDir := filepath.Join(userConfigDir, "go-librespot")
f.StringVar(&cfg.ConfigDir, "config_dir", defaultConfigDir, "the configuration directory")

var configOverrides []string
f.StringArrayVarP(&configOverrides, "conf", "c", nil, "override config values (format: field=value, use field1.field2=value for nested fields)")

err = f.Parse(os.Args[1:])
if err != nil {
return err
Expand Down Expand Up @@ -515,6 +519,26 @@ func loadConfig(cfg *Config) error {
return fmt.Errorf("failed loading command line configuration: %w", err)
}

// apply command line config overrides (-c/--conf flags)
if len(configOverrides) > 0 {
overrideMap := make(map[string]interface{})
for _, override := range configOverrides {
parts := strings.SplitN(override, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("invalid config override format: %s (expected field=value)", override)
}
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
if key == "" {
return fmt.Errorf("invalid config override: empty field name in %s", override)
}
overrideMap[key] = value
}
if err := k.Load(confmap.Provider(overrideMap, "."), nil); err != nil {
return fmt.Errorf("failed loading config overrides: %w", err)
}
}

// unmarshal configuration
if err := k.Unmarshal("", &cfg); err != nil {
return fmt.Errorf("failed to unmarshal configuration: %w", err)
Expand Down