[GH-ISSUE #444] Replace PrintTable/PrintMarkdown type switches with registry #125

Closed
opened 2026-02-26 21:33:36 +03:00 by kerem · 0 comments
Owner

Originally created by @rudrankriyam on GitHub (Feb 8, 2026).
Original GitHub issue: https://github.com/rudrankriyam/App-Store-Connect-CLI/issues/444

Problem

  • PrintTable and PrintMarkdown in internal/asc/output_core.go are huge type switches.
  • Adding a response type requires multiple edits and is easy to miss.

Proposed fix (step-by-step)

  1. Add an output registry keyed by reflect.Type, storing {table, markdown} handlers, with a registerOutput helper that guards duplicates/nil handlers.
  2. Create a one-time generator that parses the existing switches in output_core.go and emits output_registry_generated.go registrations (preserve wrapper logic in cases).
  3. Replace PrintTable and PrintMarkdown with registry lookups.
  4. Decide missing-registration behavior (clear error vs JSON fallback) and enforce it.
  5. Add tests to ensure no duplicate registrations and both table+markdown handlers exist.
  6. Remove/retire the old switch blocks.

Acceptance criteria

  • The huge switches are removed from output_core.go.
  • Adding a new type requires only registration + formatter functions.
  • Tests catch missing/duplicate registrations.
  • make test passes.
Originally created by @rudrankriyam on GitHub (Feb 8, 2026). Original GitHub issue: https://github.com/rudrankriyam/App-Store-Connect-CLI/issues/444 ## Problem - `PrintTable` and `PrintMarkdown` in `internal/asc/output_core.go` are huge type switches. - Adding a response type requires multiple edits and is easy to miss. ## Proposed fix (step-by-step) 1. Add an output registry keyed by `reflect.Type`, storing `{table, markdown}` handlers, with a `registerOutput` helper that guards duplicates/nil handlers. 2. Create a one-time generator that parses the existing switches in `output_core.go` and emits `output_registry_generated.go` registrations (preserve wrapper logic in cases). 3. Replace `PrintTable` and `PrintMarkdown` with registry lookups. 4. Decide missing-registration behavior (clear error vs JSON fallback) and enforce it. 5. Add tests to ensure no duplicate registrations and both table+markdown handlers exist. 6. Remove/retire the old switch blocks. ## Acceptance criteria - The huge switches are removed from `output_core.go`. - Adding a new type requires only registration + formatter functions. - Tests catch missing/duplicate registrations. - `make test` passes.
kerem closed this issue 2026-02-26 21:33:37 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/App-Store-Connect-CLI#125
No description provided.