Add config file loading with startup defaults and CLI override semantics#12
Merged
Conversation
Copilot
AI
changed the title
[WIP] Add Config.Load() to complement Config.Save()
Add config file loading with startup defaults and CLI override semantics
Jun 1, 2026
rustyeddy
approved these changes
Jun 1, 2026
There was a problem hiding this comment.
Pull request overview
This PR adds a missing “read” path for persisted configuration by introducing JSON config file loading, default config file discovery, and startup wiring so file-backed values are applied before CLI flag parsing (keeping explicit CLI flags as the highest precedence).
Changes:
- Added
(*Configuration).Load(path string)and(*Configuration).LoadDefault()to load JSON config from disk (with default path discovery). - Updated
main()to callconfig.LoadDefault()beforeflag.Parse()so persisted values apply as defaults. - Added unit tests for config loading and default-file fallback behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
redeye/main.go |
Loads default config files before parsing flags to apply persisted defaults at startup. |
config.go |
Implements Load and LoadDefault for JSON config reading and default path discovery. |
config_test.go |
Adds tests covering Load success/read errors and LoadDefault selection order. |
go.mod |
Tidies module requirements formatting/order. |
go.sum |
Updates checksums for added/transitive dependencies after module tidying. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
32
to
37
| func main() { | ||
| if err := config.LoadDefault(); err != nil { | ||
| log.Fatalf("failed to load default config: %+v", err) | ||
| } | ||
|
|
||
| flag.Parse() |
Comment on lines
+54
to
+60
| func TestConfigurationLoadError(t *testing.T) { | ||
| cfg := &Configuration{} | ||
| err := cfg.Load(filepath.Join(t.TempDir(), "missing.json")) | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), "failed to read file") | ||
| } | ||
|
|
Comment on lines
+69
to
+70
| homeDir := t.TempDir() | ||
| t.Setenv("HOME", homeDir) |
Comment on lines
+90
to
+91
| homeDir := t.TempDir() | ||
| t.Setenv("HOME", homeDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Configurationsupported JSON persistence viaSavebut had no complementary read path, forcing full flag specification on every run. This change introduces config file loading and wires default file discovery into startup so persisted values are applied before flags are parsed.Configuration read support
(*Configuration).Load(path string) errorto read JSON from disk and unmarshal into the active config struct.Default config discovery
(*Configuration).LoadDefault() errorto attempt, in order:redeye.json(working directory)~/.redeye.json(user home)Startup integration (flag precedence preserved)
main()now callsconfig.LoadDefault()beforeflag.Parse(), so file-backed defaults are loaded first and explicit CLI flags continue to win.