Repository navigation
Description
Overview
Add JSON output format support to the destroy command (roadmap task 12.9). This is part of Phase 2 of the JSON output epic (#348), which aims to implement JSON output for all remaining commands so that JSON can eventually become the default output format.
The destroy command currently only outputs human-readable text progress messages and a purge hint. This task adds a machine-readable JSON alternative that automation workflows, CI/CD pipelines, and AI agents can parse programmatically.
Key characteristic: Unlike most commands, destroy accepts environments in any state. As a result, the instance_ip field in the output DTO may be null if the environment was never provisioned. The JSON schema must handle this nullable field, consistent with the release command pattern.
Specification
See detailed specification: docs/issues/386-add-json-output-to-destroy-command.md
🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path: src/presentation/cli/views/commands/destroy/
Pattern: Strategy Pattern for rendering (same as provision, create, show, run, list, configure, release, test)
Module Structure Requirements
- Follow the existing view module structure established in
release/(hasview_data/) -
DestroyDetailsDatais a plain presentation DTO derivingSerialize,PartialEq(notDeserialize) with aFrom<&Environment<Destroyed>>impl -
JsonView::render()returnsString— serialization errors handled inline viaunwrap_or_else -
TextView::render()formats the same data as human-readable text and also returnsString
Architectural Constraints
- No business logic in presentation layer — only rendering
- Error handling follows project conventions
- Output must go through
UserOutputmethods — neverprintln!oreprintln!directly - The
DestroyDetailsDataDTO must deriveserde::Serialize(output-only — noDeserializeneeded)
Anti-Patterns to Avoid
- ❌ Mixing rendering concerns in the controller
- ❌ Adding business logic to view structs
- ❌ Using
println!/eprintln!instead ofUserOutput
Implementation Plan
Phase 1: View Module
- Create
src/presentation/cli/views/commands/destroy/directory andmod.rs - Implement
DestroyDetailsDataDTO withFrom<&Environment<Destroyed>>conversion inview_data/destroy_details.rs - Implement
JsonView::render()inviews/json_view.rs - Implement
TextView::render()inviews/text_view.rs
Phase 2: Controller + Router
- Add
output_format: OutputFormatparameter toDestroyCommandController::execute() - Update
complete_workflow()to accept&Environment<Destroyed>andoutput_format - Move purge hint to text-only branch
- Update router to pass
output_formatfrom context to controller
Phase 3: Tests + Docs
- Unit tests for
DestroyDetailsData::from()(with and without IP) - Unit tests for
JsonView::render()(IP present, IP null) - Unit tests for
TextView::render()(IP present,N/Afor null IP) - Update
docs/user-guide/commands/destroy.mdwith JSON output examples
Acceptance Criteria
Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.
Quality Checks:
- Pre-commit checks pass:
./scripts/pre-commit.sh
Task-Specific Criteria:
-
destroy --output-format jsonoutputs valid JSON with all expected fields -
instance_ipis a string when present andnullwhen the environment was never provisioned -
destroy --output-format text(default) produces human-readable output including the purge hint - Purge hint is suppressed in JSON mode
- Unit tests cover DTO conversion, both view renderers, and the null IP case
- Documentation updated with JSON output examples
Related
- Parent: EPIC: Add JSON output format support #348 (EPIC: Add JSON output format support)
- Roadmap: section 12.9
- Reference implementation (release):
src/presentation/cli/views/commands/release/ - Reference implementation (test):
src/presentation/cli/views/commands/test/
Activity
docs: add issue specification for #386
feat: add JSON output to destroy command (#386)
docs: mark 12.8 and 12.9 as completed in roadmap
docs: mark roadmap 12.14 completed and remove closed issue docs