Skip to content

Add JSON output format to configure command #371

@josecelano

Description

@josecelano

Overview

Implement JSON output format support for the configure command (roadmap task 12.6).

This is part of Phase 2 of the JSON output epic (#348), which aims to add JSON output to all remaining commands so that JSON can eventually become the default output format.

Specification

Full implementation specification (goals, architecture, DTO definition, code patterns, acceptance criteria):

docs/issues/371-add-json-output-to-configure-command.md

Roadmap Reference

From docs/roadmap.md - section 12.6:

12.6 Add JSON output to configure command [Issue #371]

  • Rationale: Contains the list of installed/configured components (Docker, security updates, firewall) and their status
  • Allows automation to verify successful configuration before proceeding to release

Expected JSON Output

{
  "environment_name": "my-env",
  "instance_name": "torrust-tracker-vm-my-env",
  "provider": "lxd",
  "state": "Configured",
  "instance_ip": "10.140.190.39",
  "created_at": "2026-02-20T10:00:00Z"
}

Note: created_at is the single lifecycle timestamp from the domain model. There is no separate configured_at field. The exact schema is specified in the spec file linked above.

Implementation Pattern

Follow the list command pattern from PR #360 (most recent, canonical — not the older provision pattern):

  • JsonView::render() returns String (not Result) — serialization errors handled inline via unwrap_or_else fallback JSON
  • No OutputFormatting error variant needed in ConfigureSubcommandError
  • display_configure_results() uses a match output_format { Text => ..., Json => ... } Strategy Pattern
  • Router extracts output_format via context.output_format() and passes it to execute()

Key files to create/modify:

  • src/presentation/views/commands/configure/ — new module (mirrors provision/ with view_data/ subdir)
  • src/presentation/controllers/configure/handler.rs — add output_format param and display_configure_results()
  • src/presentation/dispatch/router.rs — pass output_format to execute()

Acceptance Criteria

  • configure my-env --output-format json outputs valid, parseable JSON to stdout
  • JSON output contains: environment_name, state, created_at, instance_ip
  • configure my-env (default text) continues to work unchanged
  • JsonView and TextView have unit tests following it_should_... naming convention
  • No println!/eprintln! — all output via UserOutput
  • Pre-commit checks pass: ./scripts/pre-commit.sh

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions