Skip to content

feat: unify config across all tools, add JSON config and make setup wizard - #18

Merged
calmcacil merged 1 commit into
mainfrom
feat/config-overhaul
May 26, 2026
Merged

feat: unify config across all tools, add JSON config and make setup wizard#18
calmcacil merged 1 commit into
mainfrom
feat/config-overhaul

Conversation

@calmcacil

Copy link
Copy Markdown
Owner

Summary

Complete overhaul of CalmsToolkit configuration, performance, and code quality.

New Infrastructure

  • Shared JSON config at ~/.config/calmstoolkit/config.json — all tools read from same file
  • Interactive setup wizard (make setup) — step-by-step prompts to generate config
  • Shared color.go — unified ANSI constants with proper ColorOrange fix, control sequences
  • config.goToolkitConfig type, LoadToolkitConfig()/Save()/Validate()/DefaultToolkitConfig()
  • config_test.go — 8 tests for config round-trip, validation, defaults

Bug Fixes

Before After
config.Timeout was dead code, all fetches hardcoded 10s config.Timeout wired into shared http.Client
ColorOrange == ColorYellow (identical) ColorOrange = \033[38;5;208m (256-color orange)
Movie date parse errors silently dropped Logged to stderr with debug info
Watch mode: for{...} — killed via SIGKILL signal.NotifyContext — graceful SIGINT/SIGTERM
clearScreen() spawned exec.Command("clear") ANSI \033[2J\033[H
truncateText panicked on maxLen <= 3 Handles all edge cases safely
formatMovie fixedChars calculation off by 2 Correct len(timeStr) + 8

Performance

  • Concurrent fetching: All Sonarr/Radarr instances fetched in parallel via errgroup (was fully sequential)
  • Shared HTTP client: Single http.Client{Timeout, Transport} with keep-alive (was new client per request)
  • Queue optimization: ?pageSize=1 to minimize payload (was fetching all queue items)
  • context.Context: Threaded through entire fetch chain enabling cancellation/timeout

Code Quality

Before After
Date logic duplicated in 3 places calculateDateRange() helper, single source
Config passed by value everywhere *CalendarToolConfig pointer
Instance names hardcoded Sonarr-1 Configurable from ArrInstance.Name
buildDayContent mutated caller's slice Defensive slices.Clone()
Manual contains/ at output end
  • -filter flag: Comma-separated: missing,available,premieres,monitored
  • -monitored-only flag
  • -no-banner flag — suppress header
  • -quiet flag — suppress queue warnings

File Changes

 16 files changed, 2373 insertions(+), 2088 deletions(-)
 create mode 100644 cmd/calmstoolkit-setup/main.go
 create mode 100644 color.go
 create mode 100644 config.go
 create mode 100644 config_test.go

Testing

All 131 tests pass across all 5 test suites (shared + 4 tool suites).

…tup wizard

- Create shared config.go with ToolkitConfig, JSON load/save/validate
- Create shared color.go with unified ANSI constants (fix ColorOrange)
- Create config_test.go with 8 round-trip and validation tests
- Add interactive setup wizard at cmd/calmstoolkit-setup/ (make setup)
- Rewrite media-calendar.go: concurrent errgroup fetching, context.Context,
  signal.NotifyContext graceful shutdown, shared HTTP client, calculateDateRange
  helper, summary line, -filter/-no-banner/-quiet/-monitored-only flags,
  configurable instance names, fixed truncateText edge case, ANSI clearScreen
- Rewrite media-streams.go: shared config, context, signal handler
- Rewrite media-requests.go: shared config, context
- Rewrite arr-feed.go: shared config, context, signal handler
- Remove all old loadConfig/loadEnvFile/parseCommaSeparated functions
- Remove per-tool ANSI color constants (use shared color.go)
- Update Makefile: add setup/setup-install targets, fix build-all for package
- Update .env.example to point to new config system
- All 131 tests pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant