feat: [#355] add JSON output to show command#356
Merged
josecelano merged 2 commits intomainfrom Feb 17, 2026
Merged
Conversation
11 tasks
67d9ca2 to
09dfda7
Compare
Member
Author
|
ACK 09dfda7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds JSON output format support to the
showcommand, enabling machine-readable environment information for automation and scripting. This implements #355 and contributes to Phase 1 of EPIC #348 (JSON output for high-value commands).Changes
Implementation
DTOs with Serialization (Application Layer):
#[derive(Serialize)]to all show command DTOs:EnvironmentInfo,InfrastructureInfoServiceInfo,LocalhostServiceInfo,TlsDomainInfoPrometheusInfo,GrafanaInfoJsonView (Presentation Layer):
JsonViewstruct withrender()method usingserde_json::to_string_pretty()views/module:TextViewin separate file, newmod.rswith re-exportsController Wiring:
showcontroller to acceptoutput_format: OutputFormatmatch output_format { Text => TextView, Json => JsonView }context.output_format()throughDocumentation
docs/user-guide/commands/show.md:--output-formatoption documentationjqfor JSON parsingUsage
Examples
Provisioned State (JSON)
{ "name": "my-environment", "state": "Provisioned", "provider": "LXD", "created_at": "2026-02-16T17:56:43.788700279Z", "infrastructure": { "instance_ip": "10.140.190.85", "ssh_port": 22, "ssh_user": "torrust", "ssh_key_path": "/home/user/.ssh/torrust_key" }, "services": null, "prometheus": null, "grafana": null, "state_name": "provisioned" }Running State (JSON)
{ "name": "my-environment", "state": "Running", "services": { "udp_trackers": ["udp://udp.tracker.local:6969/announce"], "https_http_trackers": ["https://http.tracker.local/announce"], "api_endpoint": "https://api.tracker.local/api", "api_uses_https": true, "health_check_url": "https://health.tracker.local/health_check", "tls_domains": [...] }, "prometheus": { "access_note": "Internal only (localhost:9090)" }, "grafana": { "url": "https://grafana.tracker.local/", "uses_https": true }, "state_name": "running" }Automation Example
Testing
Unit Tests
json_view.rs:it_should_render_json_for_created_stateit_should_render_json_for_provisioned_stateit_should_produce_valid_json(validates withserde_json::from_str)Manual Testing
Verified with real environments:
Linters
-- -D warningsArchitecture
Follows the Strategy Pattern established in:
createcommandprovisioncommandBenefits from refactor PR #354 which properly organized the views module structure.
Roadmap Progress
createcommand JSON output (Add JSON Output to create Command #349) ✅ Mergedprovisioncommand JSON output (Add JSON output to provision command #352) ✅ Mergedshowcommand JSON output (Add JSON output to show command #355) ✅ This PRruncommand JSON outputlistcommand JSON outputRelated Issues
Checklist