Skip to content

Conversation

@josecelano
Copy link
Member

Description

Implements the show command to display environment information with state-aware details. This command provides a read-only view of stored environment data, making it fast and reliable for users to inspect their deployment state.

Issue: Closes #241

Changes

Phase 1-5: Core Implementation ✅

  • Added CLI subcommand and command dispatch
  • Implemented ShowCommandHandler with state-aware extraction
  • Created DTOs for environment info display
  • Added comprehensive error handling with actionable messages
  • Implemented MVC pattern with EnvironmentInfoView
  • Added output formatting with UserOutput (no direct println!/eprintln!)
  • Full unit test coverage for all states and error scenarios
  • E2E tests for command validation

Phase 6: Creation Timestamp ✅

  • Added created_at field to RuntimeOutputs domain model
  • create command now populates creation timestamp using Clock service
  • show command displays when environment was created
  • Backward compatible with #[serde(default)]

Phase 7: Service URLs in RuntimeOutputs ✅

  • Added service_endpoints field to RuntimeOutputs with ServiceEndpoints struct
  • Added url crate dependency for proper URL handling
  • run command stores service URLs after successful startup
  • show command displays stored URLs with fallback to computing from config
  • Refactored ServiceEndpoints::from_tracker_config into focused helper methods

Features

  • State-aware display: Shows different information based on environment state (Created, Provisioned, Configured, Released, Running)
  • Fast execution: < 100ms typical (reads stored data, no network calls)
  • Clear error messages: Actionable guidance for all error scenarios
  • Human-friendly output: Formatted with colors, spacing, and next-step guidance
  • Creation timestamp: Shows when each environment was created
  • Service URLs: Displays all tracker service endpoints for Running state

Testing

  • ✅ All pre-commit checks pass
  • ✅ Unit tests for all handler logic, states, and error scenarios
  • ✅ E2E tests validate command execution and error handling
  • ✅ Manual testing verified for Created state and error cases
  • ✅ Doc tests pass
  • ✅ Test coverage comprehensive

Architecture

  • DDD Layers: Application (handler, DTOs, errors) + Presentation (CLI, view)
  • Patterns: Command Handler, MVC (stateless view), DTO
  • Output: All output via UserOutput (no direct stdio usage)
  • Errors: Explicit enum types with thiserror (not anyhow)
  • Module organization: Follows project conventions (imports first, public items at top)

Documentation

  • Issue spec updated with all phases marked complete
  • Inline code documentation (doc comments)
  • Command help text available in --help

Related

  • Feature specification: docs/features/environment-status-command/
  • Architecture docs: docs/codebase-architecture.md, docs/contributing/ddd-layer-placement.md
  • Output handling: docs/contributing/output-handling.md
  • Error handling: docs/contributing/error-handling.md

Example Usage

# Show Created environment
$ torrust-tracker-deployer show my-environment
Environment: my-environment
State: Created
Provider: LXD
Created: 2026-01-07 12:11:29 UTC

Run 'provision' to create infrastructure.

# Error handling
$ torrust-tracker-deployer show non-existent
❌ Show command failed: Environment 'non-existent' not found
Tip: Use 'list' command to see available environments

- Add Show variant to Commands enum with environment parameter
- Create ShowCommandController with 3-step workflow:
  1. Validate environment name
  2. Load environment from repository
  3. Display basic information
- Add ShowSubcommandError with help() method for actionable errors
- Integrate show command into router dispatch
- Add container factory method for show controller
- Add provider_name() method to AnyEnvironmentState

Phase 1 implements basic CLI skeleton that validates input,
loads environment state, and displays minimal information
including name, state, and provider.
- Create ShowCommandHandler in application layer
- Add EnvironmentInfo and InfrastructureInfo DTOs
- Add ShowCommandHandlerError with actionable help messages
- Update presentation controller to delegate to application handler
- Include state-aware next_step guidance
- Add unit tests for state formatting and guidance
- Add ShowCommandHandler::get_environment_info() for state-based data extraction
- Add ServiceInfo struct for Released/Running states with tracker service details
- Add EnvironmentInfoView following MVC pattern (stateless render function)
- Refactor ShowCommandController to use EnvironmentInfoView
- Add comprehensive unit tests for view rendering
- Add comprehensive user guide for show command (docs/user-guide/commands/show.md)
- Update console-commands.md with show command specification
- Add show to commands README.md and state transitions table
…tracker_config

- Extract build_udp_tracker_urls() for UDP tracker URL construction
- Extract build_http_tracker_urls() for HTTP tracker URL construction
- Extract build_api_endpoint_url() for API endpoint URL construction
- Extract build_health_check_url() for health check URL construction
@josecelano josecelano self-assigned this Jan 7, 2026
@josecelano
Copy link
Member Author

ACK 9d71a0b

@josecelano josecelano merged commit 7972040 into main Jan 7, 2026
34 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.

Implement Environment Show Command

2 participants