Repository navigation
Description
Parent Epic: #348 - Add JSON output format support
Related: Roadmap Section 12.3, #349 ✅ Completed, #352 ✅ Completed
Overview
Add machine-readable JSON output format (--output-format json) to the show command. This enables automation workflows and AI agents to programmatically extract environment state, instance IP address, and service URLs without parsing human-readable text.
Goals
- Implement JSON output format for show command
- Preserve existing human-readable output as default
- Enable automation to extract instance IP and comprehensive environment state
- Follow the architecture pattern established in Add JSON Output to create Command #349 and Add JSON output to provision command #352
Implementation Approach
Step 1: Add Serde Derives to DTOs
The EnvironmentInfo and related DTOs in src/application/command_handlers/show/info/ need #[derive(Serialize)]:
EnvironmentInfoInfrastructureInfoServiceInfo(ininfo/tracker.rs)PrometheusInfo(ininfo/prometheus.rs)GrafanaInfo(ininfo/grafana.rs)TlsDomainInfo(ininfo/tracker.rs)LocalhostServiceInfo(ininfo/tracker.rs)
Step 2: Reorganize Views Module
Following the refactor from PR #354 (Separate View Data from Views):
src/presentation/views/commands/show/
├── views/
│ ├── mod.rs (Re-exports TextView and JsonView)
│ ├── text_view.rs (Renamed from mod.rs - TextView implementation)
│ ├── json_view.rs (NEW - JsonView implementation)
│ └── ... (existing helper modules for TextView)
└── mod.rsStep 3: Create JsonView
Simple JSON serialization using serde_json::to_string_pretty() on the EnvironmentInfo DTO.
Step 4: Update Controller
Wire view selection in src/presentation/controllers/show/handler.rs:
let output = match ctx.output_format() {
OutputFormat::Text => TextView::render(&info),
OutputFormat::Json => JsonView::render(&info),
};CLI Interface
# Human-readable output (default, unchanged)
torrust-tracker-deployer show my-env
# JSON output (new)
torrust-tracker-deployer show my-env --output-format json
# Short form
torrust-tracker-deployer show my-env -o jsonSuccess Criteria
- JSON output correctly serializes
EnvironmentInfoand nested DTOs - JSON output varies correctly by state (created → provisioned → running)
- Text output remains unchanged (existing tests pass)
- Unit tests cover all state variations
- Manual testing validates real-world usage
- All linters pass
- User documentation updated
Documentation
Full specification: docs/issues/355-add-json-output-to-show-command.md
Roadmap Task: 12.3
Pattern: Strategy Pattern (established in #349 and #352)
Architecture: Presentation layer only - no changes to application or domain layers
Activity
docs: [#355] add specification for JSON output in show command
feat: [#355] add JSON output to show command
docs: [#355] add JSON output format documentation for show command
docs: [#355] add JSON output format documentation for show command
Merge #356: feat: [#355] add JSON output to show command
feat: [#357] add JSON output to run command
Merge #358: Add JSON Output to Run Command
Merge #360: Add JSON Output to List Command
chore: remove closed issue documentation files