Summary
Identical printJSON() in 3 files. Output formatting coupled to os.Stdout.
Current State
Duplicated in:
internal/cmd/mail/output.go:19-23
internal/cmd/calendar/output.go:18-22
internal/cmd/contacts/output.go:18-22
func printJSON(data any) error {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(data)
}
Problems
- DRY violation - changes must be applied 3 times
- Output coupled to stdout - cannot test output format
- No flexibility for different output targets
Proposed Solution
Create internal/output package:
func PrintJSON(w io.Writer, data any) error
func PrintTable(w io.Writer, headers []string, rows [][]string) error
Benefits:
- Single implementation
- Testable (pass bytes.Buffer)
- Flexible output targets
Priority
P2 - Code quality improvement