Skip to content

feat(tracker-client): add HTTP response format option#1758

Merged
josecelano merged 2 commits into
torrust:developfrom
josecelano:1562-http-tracker-client-format-option
May 11, 2026
Merged

feat(tracker-client): add HTTP response format option#1758
josecelano merged 2 commits into
torrust:developfrom
josecelano:1562-http-tracker-client-format-option

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Implements issue #1562 by adding output format selection to the HTTP tracker client.

Changes included

  • Add --format option to HTTP announce and scrape commands.
  • Support output values:
    • compact (default)
    • pretty
  • Add format-aware serialization helper and use it for announce/scrape outputs.
  • Apply selected format to fallback JSON output (when bencode can be converted to JSON).
  • Keep raw-bytes fallback unchanged as plain text warning output.
  • Update module examples to include pretty output usage.
  • Add focused unit tests for compact vs pretty serialization.

Manual verification

Verified locally against http://127.0.0.1:7070:

  • announce --format compact outputs single-line JSON.
  • announce --format pretty outputs indented multiline JSON.
  • scrape (without --format) outputs compact single-line JSON.
  • Invalid --format value is rejected by clap with allowed values.

Verification

  • cargo test -p torrust-tracker-client console::clients::http::app::tests
  • cargo check -p torrust-tracker-client
  • linter all
  • cargo machete

Issue

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --format output option to the HTTP tracker client so users can choose between compact (single-line) and pretty (indented) JSON output for announce and scrape, addressing the “pretty JSON” request in issue #1562.

Changes:

  • Introduces an OutputFormat clap ValueEnum (compact default, pretty) for announce and scrape.
  • Adds a format-aware serialize_json helper and applies it to typed responses and the JSON fallback path.
  • Updates module-level examples and adds unit tests for compact vs pretty serialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread console/tracker-client/src/console/clients/http/app.rs Outdated
@josecelano josecelano self-assigned this May 11, 2026
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.40%. Comparing base (ffc7486) to head (2bfeabd).
⚠️ Report is 12 commits behind head on develop.

Files with missing lines Patch % Lines
...ole/tracker-client/src/console/clients/http/app.rs 64.00% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1758      +/-   ##
===========================================
- Coverage    79.41%   79.40%   -0.01%     
===========================================
  Files          368      368              
  Lines        27160    27182      +22     
  Branches     27160    27182      +22     
===========================================
+ Hits         21568    21584      +16     
- Misses        5309     5314       +5     
- Partials       283      284       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano

Copy link
Copy Markdown
Member Author

ACK 2bfeabd

@josecelano josecelano merged commit cfc5cd1 into torrust:develop May 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP Tracker client: Add option to show response in pretty JSON

2 participants