feat: support custom --config path in CLI and GUI

Add config.LoadFrom/SaveTo for arbitrary paths and thread a --config
flag through both entry points:
- CLI: --config loads a file first; explicit flags override file values
- GUI: --config selects the settings file used for load and save
- tests for LoadFrom/SaveTo and default fallback
This commit is contained in:
2026-09-19 08:35:07 +01:00
parent b9a539e133
commit 34efbaf26d
5 changed files with 128 additions and 27 deletions
+30
View File
@@ -92,3 +92,33 @@ func TestToFlingerAnnounceDefault(t *testing.T) {
t.Error("ToFlinger announce default should be true")
}
}
// TestLoadFromMissing returns defaults for a non-existent custom path.
func TestLoadFromMissing(t *testing.T) {
c, err := LoadFrom(filepath.Join(t.TempDir(), "missing", "config.json"))
if err != nil {
t.Fatalf("LoadFrom: %v", err)
}
if c.Port != 9756 {
t.Errorf("default port = %d, want 9756", c.Port)
}
}
// TestSaveToLoadFromRoundTrip uses an explicit path independent of pathVar.
func TestSaveToLoadFromRoundTrip(t *testing.T) {
p := filepath.Join(t.TempDir(), "custom", "daemon.json")
announce := false
want := Config{Name: "Daemon", Port: 9901, Quality: 90, FPS: 30, Source: "screen", Audio: true, Announce: &announce}
if err := SaveTo(p, want); err != nil {
t.Fatalf("SaveTo: %v", err)
}
got, err := LoadFrom(p)
if err != nil {
t.Fatalf("LoadFrom: %v", err)
}
if got.Name != want.Name || got.Port != want.Port || *got.Announce != false {
t.Errorf("round trip mismatch: got %+v want %+v", got, want)
}
}