Skip to content

Add JSON Output to List Command#360

Merged
josecelano merged 3 commits intomainfrom
359-add-json-output-to-list-command
Feb 17, 2026
Merged

Add JSON Output to List Command#360
josecelano merged 3 commits intomainfrom
359-add-json-output-to-list-command

Conversation

@josecelano
Copy link
Copy Markdown
Member

Overview

Implements JSON output format for the list command, completing Phase 1 of EPIC #348 (JSON Output for High-Value Commands).

Closes: #359
Part of: #348 - Add JSON output format support

Changes

1. JSON Output Implementation

  • New: JsonView in src/presentation/views/commands/list/views/json_view.rs
    • Serializes EnvironmentList to pretty-printed JSON
    • Includes all environment data without truncation
    • Handles failed environments gracefully
    • 5 comprehensive unit tests

2. DTO Serialization Support

  • Modified: src/application/command_handlers/list/info.rs
    • Added #[derive(Serialize)] to EnvironmentSummary and EnvironmentList
    • Enables JSON serialization via serde

3. Controller Updates

  • Modified: src/presentation/controllers/list/handler.rs
    • Updated execute() to accept OutputFormat parameter
    • Implements Strategy Pattern in display_results() (TextView or JsonView)

4. Router Integration

  • Modified: src/presentation/dispatch/router.rs
    • Extracts output_format from ExecutionContext
    • Passes format to ListCommandController

5. Module Structure

  • Modified: src/presentation/views/commands/list/mod.rs
    • Re-exports both TextView and JsonView

6. Text View Enhancement

  • Modified: src/presentation/views/commands/list/views/text_view.rs
    • Increased environment name column width from 20 to 50 characters
    • Updated table separator width accordingly
    • Fixed truncation test expectations

Usage

Text Output (Default)

torrust-tracker-deployer list
# or explicitly:
torrust-tracker-deployer list --output-format text

JSON Output

torrust-tracker-deployer list --output-format json

JSON Schema Example

{
  "environments": [
    {
      "name": "production-high-availability-tracker",
      "state": "Running",
      "provider": "Hetzner Cloud",
      "created_at": "2026-02-14T16:45:00Z"
    }
  ],
  "total_count": 1,
  "failed_environments": [],
  "data_directory": "/path/to/data"
}

Benefits

  • No Truncation: JSON output provides full environment names (text format now shows 50 chars before truncating)
  • Automation Ready: Easy parsing with jq or programming languages
  • Complete Data: Includes all fields (name, state, provider, created_at)
  • Failure Handling: Failed environments included separately in JSON
  • Backward Compatible: Text output unchanged as default format

Automation Examples

# Extract all environment names
torrust-tracker-deployer list -o json | jq -r '.environments[].name'

# Filter by state
torrust-tracker-deployer list -o json | jq -r '.environments[] | select(.state == "Running") | .name'

# Count by provider
torrust-tracker-deployer list -o json | jq '.environments | group_by(.provider) | map({provider: .[0].provider, count: length})'

Testing

  • ✅ All 2,254 tests passing (including 5 new JsonView tests)
  • ✅ All linters passing (markdown, yaml, toml, cspell, clippy, rustfmt, shellcheck)
  • ✅ Build successful

Architecture

Follows the established Strategy Pattern from previous JSON output implementations:

This completes Phase 1 of the JSON output support epic.

@josecelano josecelano linked an issue Feb 17, 2026 that may be closed by this pull request
@josecelano josecelano self-assigned this Feb 17, 2026
- Add real sample outputs from full-stack environment to all command docs
- Update validate.md with full-featured environment validation output
- Update create.md with full-stack environment creation output
- Update provision.md with connection details and DNS warning
- Update configure.md with actual timing (38.2s)
- Update release.md with successful release output
- Update run.md with full service URLs (UDP/HTTP/HTTPS trackers, API, health, Grafana)
- Update test.md with realistic HTTPS failure scenario
- Update show.md with complete Running state (text and JSON outputs)
- Update destroy.md with infrastructure teardown output
- Update purge.md with successful purge output

All examples now show real command execution with actual timings, IPs,
and service URLs from a full-stack deployment with MySQL, multiple
trackers, HTTPS (Caddy), Prometheus, Grafana, and backups.
@josecelano
Copy link
Copy Markdown
Member Author

ACK 181db29

@josecelano josecelano merged commit e891f60 into main Feb 17, 2026
39 checks passed
josecelano added a commit that referenced this pull request Feb 17, 2026
Mark task 12.5 (Add JSON output to list command) as completed with PR #360 link.
This completes Phase 1 of EPIC #348 - all 5 high-value commands now support JSON output.
This was referenced Feb 17, 2026
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.

Add JSON Output to List Command

1 participant