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
Implementation Approach
Step 1: Add Serde Derives to DTOs
The EnvironmentInfo and related DTOs in src/application/command_handlers/show/info/ need #[derive(Serialize)]:
EnvironmentInfo
InfrastructureInfo
ServiceInfo (in info/tracker.rs)
PrometheusInfo (in info/prometheus.rs)
GrafanaInfo (in info/grafana.rs)
TlsDomainInfo (in info/tracker.rs)
LocalhostServiceInfo (in info/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.rs
Step 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 json
Success Criteria
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
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 theshowcommand. This enables automation workflows and AI agents to programmatically extract environment state, instance IP address, and service URLs without parsing human-readable text.Goals
Implementation Approach
Step 1: Add Serde Derives to DTOs
The
EnvironmentInfoand related DTOs insrc/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):
Step 3: Create JsonView
Simple JSON serialization using
serde_json::to_string_pretty()on theEnvironmentInfoDTO.Step 4: Update Controller
Wire view selection in
src/presentation/controllers/show/handler.rs:CLI Interface
Success Criteria
EnvironmentInfoand nested DTOsDocumentation
Full specification:
docs/issues/355-add-json-output-to-show-command.mdRoadmap Task: 12.3
Pattern: Strategy Pattern (established in #349 and #352)
Architecture: Presentation layer only - no changes to application or domain layers