Skip to content

feat: add JSON output to validate command (12.10)#391

Merged
josecelano merged 1 commit into
mainfrom
390-add-json-output-to-validate-command
Feb 26, 2026
Merged

feat: add JSON output to validate command (12.10)#391
josecelano merged 1 commit into
mainfrom
390-add-json-output-to-validate-command

Conversation

@josecelano
Copy link
Copy Markdown
Member

Overview

Closes #390 — Part of EPIC #348 (roadmap task 12.10).

Adds JSON output format support to the validate command. When --output-format json is passed, the command outputs a machine-readable JSON object to stdout. The existing human-readable text output is fully preserved.

Changes

New files

  • src/presentation/cli/views/commands/validate/mod.rs — module declaration
  • src/presentation/cli/views/commands/validate/view_data/validate_details.rsValidateDetailsData DTO with from_result(&Path, &ValidationResult) constructor
  • src/presentation/cli/views/commands/validate/views/json_view.rsJsonView with unit tests
  • src/presentation/cli/views/commands/validate/views/text_view.rsTextView with unit tests

Modified files

  • src/presentation/cli/controllers/validate/handler.rs — add output_format: OutputFormat param to execute(), refactor complete_workflow() to dispatch to TextView/JsonView
  • src/presentation/cli/dispatch/router.rs — pass context.output_format() to controller
  • src/presentation/cli/views/commands/mod.rs — register pub mod validate
  • docs/user-guide/commands/validate.md — add JSON output section

JSON Output

cargo run -- validate --env-file envs/lxd-local-example.json --output-format json 2>/dev/null
{
  "environment_name": "lxd-local-example",
  "config_file": "envs/lxd-local-example.json",
  "provider": "lxd",
  "is_valid": true,
  "has_prometheus": true,
  "has_grafana": true,
  "has_https": false,
  "has_backup": false
}

Text Output (unchanged)

cargo run -- validate --env-file envs/lxd-local-example.json 2>&1
⏳ [1/3] Loading configuration file...
⏳   ✓ Configuration file loaded (took 0ms)
⏳ [2/3] Validating JSON schema...
⏳   ✓ Schema validation passed (took 0ms)
⏳ [3/3] Validating configuration fields...
⏳   ✓ Field validation passed (took 0ms)

✅ Configuration file 'envs/lxd-local-example.json' is valid

Environment Details:
• Name: lxd-local-example
• Provider: lxd
• Prometheus: Enabled
• Grafana: Enabled
• HTTPS: Disabled
• Backups: Disabled

Quality Checks

  • cargo run --bin linter all passes (stable + nightly)
  • cargo machete — no unused dependencies
  • cargo test — 417 tests pass, 0 failures
  • Text output manually verified identical to pre-change output
  • JSON output manually verified matches spec

Related

@josecelano josecelano self-assigned this Feb 26, 2026
@josecelano josecelano force-pushed the 390-add-json-output-to-validate-command branch from af4ae57 to 245b429 Compare February 26, 2026 19:26
Closes #390

- Add ValidateDetailsData DTO with from_result() constructor
  (src/presentation/cli/views/commands/validate/view_data/validate_details.rs)
- Add JsonView: renders JSON via serde_json with fallback on error
  (src/presentation/cli/views/commands/validate/views/json_view.rs)
- Add TextView: renders human-readable text preserving existing output
  (src/presentation/cli/views/commands/validate/views/text_view.rs)
- Add output_format param to ValidateCommandController::execute()
- Dispatch to JsonView/TextView in complete_workflow() via Strategy Pattern
- Router: pass context.output_format() to controller
- Update docs/user-guide/commands/validate.md with JSON section

Text output is identical to pre-change output (verified manually).
JSON output fields: environment_name, config_file, provider, is_valid,
has_prometheus, has_grafana, has_https, has_backup
@josecelano josecelano force-pushed the 390-add-json-output-to-validate-command branch from 245b429 to 659870e Compare February 26, 2026 19:30
@josecelano
Copy link
Copy Markdown
Member Author

ACK 659870e

@josecelano josecelano merged commit fd60f63 into main Feb 26, 2026
33 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 validate command (12.10)

1 participant