Repository navigation
Description
Overview
Add JSON output format support to the validate command (roadmap task 12.10). 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 validate command currently only outputs human-readable text progress messages and a validation summary. This task adds a machine-readable JSON alternative that automation workflows, CI/CD pipelines, and AI agents can parse programmatically.
Key characteristic: The validate command takes an --env-file <PATH> argument and performs validation without creating any deployment state. Its output reflects configuration properties extracted from the file — environment name, provider, and enabled feature flags (Prometheus, Grafana, HTTPS, backup). There is no domain Environment state object involved — the DTO is built directly from ValidationResult.
Specification
See detailed specification: docs/issues/390-add-json-output-to-validate-command.md
🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path: src/presentation/cli/views/commands/validate/
Pattern: Strategy Pattern for rendering (same as provision, create, show, run, list, configure, release, test, destroy)
Module Structure Requirements
- Follow the existing view module structure established in
destroy/(hasview_data/) -
ValidateDetailsDatais a plain presentation DTO derivingSerialize,PartialEq(notDeserialize) with a named constructorfrom_result(&Path, &ValidationResult) -
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
ValidateDetailsDataDTO 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/validate/mod.rs - Implement
ValidateDetailsDataDTO withfrom_result()constructor inview_data/validate_details.rs - Implement
JsonView::render()inviews/json_view.rs - Implement
TextView::render()inviews/text_view.rs - Register
validateinsrc/presentation/cli/views/commands/mod.rs
Phase 2: Controller + Router
- Add
output_format: OutputFormatparameter toValidateCommandController::execute() - Refactor
complete_workflow()to accept and dispatch onoutput_format - Update router to pass
output_formatfrom context to controller
Phase 3: Tests + Manual Verification + Docs
- Unit tests for
JsonView::render() - Unit tests for
TextView::render() - Manual verification: run
cargo run -- validate --env-file envs/lxd-local-example.jsonand confirm text output is unchanged - Manual verification: run
cargo run -- validate --env-file envs/lxd-local-example.json --output-format json 2>/dev/nulland confirm JSON output matches spec - Update
docs/user-guide/commands/validate.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:
-
validate --output-format jsonoutputs valid JSON with all expected fields -
validate --output-format text(default) produces human-readable output identical to current output - Unit tests cover both view renderers
- Documentation updated with JSON output examples
Related
- Parent: EPIC: Add JSON output format support #348 (EPIC: Add JSON output format support)
- Roadmap: section 12.10
- Reference implementation (destroy):
src/presentation/cli/views/commands/destroy/ - Reference implementation (test):
src/presentation/cli/views/commands/test/
Activity
docs: add spec and roadmap link for issue #390
feat: add JSON output to validate command (12.10)
feat: add JSON output to validate command (12.10)
feat: add JSON output to validate command (12.10)
Merge #391: feat: add JSON output to validate command (12.10)
docs: mark roadmap 12.14 completed and remove closed issue docs