Skip to content

refactor: extract shared output utilities to internal/output package #43

@rianjs

Description

@rianjs

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

  1. DRY violation - changes must be applied 3 times
  2. Output coupled to stdout - cannot test output format
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions