Skip to main content

torrust_tracker_deployer_lib/presentation/cli/controllers/destroy/
mod.rs

1//! Destroy Command Presentation Module
2//!
3//! This module implements the CLI presentation layer for the destroy command,
4//! handling argument processing and user interaction.
5//!
6//! ## Architecture
7//!
8//! The destroy command presentation layer follows the DDD pattern, orchestrating
9//! the application layer's `DestroyCommandHandler` while providing user-friendly
10//! output and error handling.
11//!
12//! ## Components
13//!
14//! - `errors` - Presentation layer error types with `.help()` methods
15//! - `handler` - Main command handler orchestrating the workflow
16//!
17//! ## Usage Example
18//!
19//! ### Basic Usage
20//!
21//! ```ignore
22//! use std::path::Path;
23//! use std::sync::Arc;
24//! use torrust_tracker_deployer_lib::bootstrap::Container;
25//! use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
26//! use torrust_tracker_deployer_lib::presentation::cli::controllers::destroy;
27//! use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
28//!
29//! # #[tokio::main]
30//! # async fn main() {
31//! let container = Container::new(VerbosityLevel::Normal, Path::new("."));
32//! let context = ExecutionContext::new(Arc::new(container), global_args);
33//!
34//! // Call the destroy handler
35//! let result = context
36//!     .container()
37//!     .create_destroy_controller()
38//!     .execute("my-environment")
39//!     .await;
40//! # }
41//! ```
42//!
43//! ### Direct Usage (For Testing)
44//!
45//! ```ignore
46//! use std::path::Path;
47//! use std::sync::Arc;
48//! use torrust_tracker_deployer_lib::bootstrap::Container;
49//! use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
50//! use torrust_tracker_deployer_lib::presentation::cli::controllers::destroy;
51//! use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
52//!
53//! # #[tokio::main]
54//! # async fn main() {
55//! let container = Container::new(VerbosityLevel::Normal, Path::new("."));
56//! let context = ExecutionContext::new(Arc::new(container), global_args);
57//!
58//! if let Err(e) = context
59//!     .container()
60//!     .create_destroy_controller()
61//!     .execute("test-env")
62//!     .await
63//! {
64//!     eprintln!("Destroy failed: {e}");
65//!     eprintln!("\n{}", e.help());
66//! }
67//! # }
68//! ```
69//!
70//! ## Direct Usage (For Testing)
71//!
72//! ```ignore
73//! use std::path::{Path, PathBuf};
74//! use std::sync::Arc;
75//! use std::time::Duration;
76//! use parking_lot::ReentrantMutex;
77//! use std::cell::RefCell;
78//! use torrust_tracker_deployer_lib::presentation::cli::controllers::destroy::handler::DestroyCommandController;
79//! use torrust_tracker_deployer_lib::presentation::cli::views::{UserOutput, VerbosityLevel};
80//! use torrust_tracker_deployer_lib::infrastructure::persistence::file_repository_factory::FileRepositoryFactory;
81//! use torrust_tracker_deployer_lib::shared::clock::SystemClock;
82//!
83//! # #[tokio::main]
84//! # async fn main() {
85//! let output = Arc::new(ReentrantMutex::new(RefCell::new(UserOutput::new(VerbosityLevel::Normal))));
86//! let data_dir = PathBuf::from("./data");
87//! let file_repository_factory = FileRepositoryFactory::new(Duration::from_secs(30));
88//! let repository = file_repository_factory.create(data_dir);
89//! let clock = Arc::new(SystemClock);
90//! if let Err(e) = DestroyCommandController::new(repository, clock, output).execute("test-env").await {
91//!     eprintln!("Destroy failed: {e}");
92//!     eprintln!("\n{}", e.help());
93//! }
94//! # }
95//! ```
96
97pub mod errors;
98pub mod handler;
99pub use handler::DestroyCommandController;
100
101#[cfg(test)]
102mod tests;
103
104// Re-export commonly used types for convenience
105pub use errors::DestroySubcommandError;