Skip to content

feat: [#377] Add JSON output to release command#379

Merged
josecelano merged 1 commit into
mainfrom
377-add-json-output-to-release-command
Feb 23, 2026
Merged

feat: [#377] Add JSON output to release command#379
josecelano merged 1 commit into
mainfrom
377-add-json-output-to-release-command

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Closes #377. Part of epic #348 (Phase 2 — JSON output for all commands).

Adds --output-format json support to the release command, following the same Strategy Pattern established by the configure command (#371).

Changes

New: src/presentation/views/commands/release/

  • view_data/release_details.rsReleaseDetailsData DTO with From<&Environment<Released>> conversion
  • views/json_view.rsJsonView::render() producing pretty-printed JSON
  • views/text_view.rsTextView::render() producing formatted human-readable text

Updated: Controller & Router

  • src/presentation/controllers/release/handler.rsexecute() now accepts output_format: OutputFormat; release_application() returns Environment<Released> instead of discarding it; complete_workflow() uses Strategy Pattern
  • src/presentation/controllers/release/tests.rs — updated existing tests to pass OutputFormat::Text
  • src/presentation/dispatch/router.rs — passes output_format from context to controller
  • src/presentation/views/commands/mod.rs — registered release module

JSON Output Example

{
  "environment_name": "my-env",
  "instance_name": "torrust-tracker-vm-my-env",
  "provider": "lxd",
  "state": "Released",
  "instance_ip": "10.140.190.101",
  "created_at": "2026-02-23T08:26:06.789141249Z"
}

Usage

torrust-tracker-deployer release my-environment --output-format json

Tests

  • Unit tests for ReleaseDetailsData::from() (conversion + state string + IP presence)
  • Unit tests for JsonView::render() (valid JSON, all fields, null IP)
  • Unit tests for TextView::render() (all sections, not-available IP, formatted timestamp)
  • All 2335 existing tests continue to pass
  • All linters pass (markdown, yaml, toml, cspell, clippy, rustfmt, shellcheck)

Reference Implementation

Follows the pattern from configure command (src/presentation/views/commands/configure/).

- Add ReleaseDetailsData DTO (mirrors ConfigureDetailsData pattern)
  - Fields: environment_name, instance_name, provider, state, instance_ip, created_at
  - Derives Debug, Clone, PartialEq, Serialize
  - From<&Environment<Released>> conversion in presentation layer

- Add JsonView and TextView for release command
  - JsonView::render() serializes to pretty-printed JSON
  - TextView::render() formats as human-readable environment details
  - Both follow Strategy Pattern from configure command

- Update ReleaseCommandController
  - execute() now accepts output_format: OutputFormat parameter
  - release_application() returns Environment<Released> instead of ()
  - complete_workflow() renders via view strategy (Text or Json)

- Update router to pass output_format to release controller
- Register release views module in commands mod.rs
- Add unit tests for DTO, JsonView, and TextView
@josecelano josecelano self-assigned this Feb 23, 2026
@josecelano

Copy link
Copy Markdown
Member Author

ACK e9a9209

@josecelano
josecelano merged commit b888db7 into main Feb 23, 2026
39 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.

Add JSON output to release command

1 participant