Skip to content

Add way to list archived goals #225

@narthur

Description

@narthur

Overview

Add functionality to list archived goals in the Buzz CLI application.

Current State

  • The Beeminder API already provides an endpoint for archived goals: GET /users/{username}/goals/archived.json
  • The codebase currently only fetches and displays active goals using FetchGoals() in beeminder.go
  • The handleListCommand() in main.go handles listing active goals

Implementation Details

1. Add API Function for Archived Goals

File: beeminder.go

Add a new function similar to FetchGoals():

func FetchArchivedGoals(config *Config) ([]Goal, error)

This function should:

  • Call the Beeminder API endpoint: /api/v1/users/{username}/goals/archived.json
  • Use the same authentication pattern as FetchGoals()
  • Return a slice of Goal objects
  • Include proper error handling and logging

2. Add CLI Command

File: main.go

Add a new command-line flag or subcommand to list archived goals. Options:

  • Option A: Add a flag to existing list command: buzz list --archived
  • Option B: Create separate command: buzz list-archived or buzz archived

Recommended: Option A for consistency with potential future filters.

3. Display Formatting

Use the existing display patterns from handleListCommand() and handleFilteredCommand():

  • Show slug, title, and other relevant metadata
  • Consider showing archive date if available
  • Maintain consistent formatting with active goal lists

4. Filter Support (Optional Enhancement)

Consider allowing filters on archived goals:

  • Search by slug or title
  • Filter by goal type
  • Sort options (by slug, archive date, etc.)

Technical Considerations

API Response

The archived goals endpoint returns the same Goal structure as active goals, making integration straightforward.

Error Handling

  • Handle cases where user has no archived goals
  • Provide clear error messages for API failures
  • Follow existing error handling patterns in the codebase

Testing

Add tests following the existing patterns:

  • Unit tests for FetchArchivedGoals() (similar to tests in beeminder_test.go)
  • Integration tests for the CLI command
  • Mock server tests for API interactions

Code Patterns

Follow existing conventions:

  • Use LogRequest() and LogResponse() for API calls
  • Follow the error wrapping pattern: fmt.Errorf("failed to...: %w", err)
  • Maintain consistency with existing command handlers

Suggested Implementation Order

  1. Add FetchArchivedGoals() function in beeminder.go
  2. Add corresponding tests in beeminder_test.go
  3. Add CLI command/flag in main.go
  4. Add command handler function
  5. Update documentation (README.md, help text)
  6. Test end-to-end functionality

Related Files

  • beeminder.go - API functions
  • main.go - CLI commands and handlers
  • beeminder_test.go - API function tests
  • model.go - Data structures (may need updates if archived goals need special handling)

Additional Notes

  • The Goal struct already has fields like won, lost, and frozen that may indicate archive status
  • Consider whether archived goals should be excluded from other commands (e.g., buzz next)
  • Archived goals likely won't have meaningful losedate or urgency data

Metadata

Metadata

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