Skip to content

Add JSON output to destroy command (12.9) #386

Closed

Description

@josecelano

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/ (has view_data/)
  • DestroyDetailsData is a plain presentation DTO deriving Serialize, PartialEq (not Deserialize) with a From<&Environment<Destroyed>> impl
  • JsonView::render() returns String — serialization errors handled inline via unwrap_or_else
  • TextView::render() formats the same data as human-readable text and also returns String

Architectural Constraints

  • No business logic in presentation layer — only rendering
  • Error handling follows project conventions
  • Output must go through UserOutput methods — never println! or eprintln! directly
  • The DestroyDetailsData DTO must derive serde::Serialize (output-only — no Deserialize needed)

Anti-Patterns to Avoid

  • ❌ Mixing rendering concerns in the controller
  • ❌ Adding business logic to view structs
  • ❌ Using println!/eprintln! instead of UserOutput

Implementation Plan

Phase 1: View Module

  • Create src/presentation/cli/views/commands/destroy/ directory and mod.rs
  • Implement DestroyDetailsData DTO with From<&Environment<Destroyed>> conversion in view_data/destroy_details.rs
  • Implement JsonView::render() in views/json_view.rs
  • Implement TextView::render() in views/text_view.rs

Phase 2: Controller + Router

  • Add output_format: OutputFormat parameter to DestroyCommandController::execute()
  • Update complete_workflow() to accept &Environment<Destroyed> and output_format
  • Move purge hint to text-only branch
  • Update router to pass output_format from 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/A for null IP)
  • Update docs/user-guide/commands/destroy.md with 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 json outputs valid JSON with all expected fields
  • instance_ip is a string when present and null when 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/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions