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
- Add
FetchArchivedGoals() function in beeminder.go
- Add corresponding tests in
beeminder_test.go
- Add CLI command/flag in
main.go
- Add command handler function
- Update documentation (README.md, help text)
- 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
Overview
Add functionality to list archived goals in the Buzz CLI application.
Current State
GET /users/{username}/goals/archived.jsonFetchGoals()inbeeminder.gohandleListCommand()inmain.gohandles listing active goalsImplementation Details
1. Add API Function for Archived Goals
File:
beeminder.goAdd a new function similar to
FetchGoals():This function should:
/api/v1/users/{username}/goals/archived.jsonFetchGoals()Goalobjects2. Add CLI Command
File:
main.goAdd a new command-line flag or subcommand to list archived goals. Options:
buzz list --archivedbuzz list-archivedorbuzz archivedRecommended: Option A for consistency with potential future filters.
3. Display Formatting
Use the existing display patterns from
handleListCommand()andhandleFilteredCommand():4. Filter Support (Optional Enhancement)
Consider allowing filters on archived goals:
Technical Considerations
API Response
The archived goals endpoint returns the same
Goalstructure as active goals, making integration straightforward.Error Handling
Testing
Add tests following the existing patterns:
FetchArchivedGoals()(similar to tests inbeeminder_test.go)Code Patterns
Follow existing conventions:
LogRequest()andLogResponse()for API callsfmt.Errorf("failed to...: %w", err)Suggested Implementation Order
FetchArchivedGoals()function inbeeminder.gobeeminder_test.gomain.goRelated Files
beeminder.go- API functionsmain.go- CLI commands and handlersbeeminder_test.go- API function testsmodel.go- Data structures (may need updates if archived goals need special handling)Additional Notes
Goalstruct already has fields likewon,lost, andfrozenthat may indicate archive statusbuzz next)losedateor urgency data