Skip to content

refactor: extract shared calendar event listing helper #44

@rianjs

Description

@rianjs

Summary

today.go, week.go, events.go share nearly identical patterns for listing events.

Current State

Duplicated patterns in:

  • internal/cmd/calendar/today.go:39-77
  • internal/cmd/calendar/week.go:39-79
  • internal/cmd/calendar/events.go:49-109

All follow the same pattern:

  1. Create client
  2. Calculate time bounds
  3. Call client.ListEvents()
  4. Check for empty results
  5. Parse events
  6. Output JSON or text

Main differences:

  • How time bounds are calculated
  • The max results limit (50 vs 100 vs configurable)
  • The header message

Proposed Solution

Extract shared helper function:

type EventListOptions struct {
    CalendarID string
    TimeMin    time.Time
    TimeMax    time.Time
    MaxResults int64
    JSONOutput bool
    Header     string
}

func listAndPrintEvents(client *calendar.Client, opts EventListOptions) error

Priority

P2 - Reduces code duplication

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