Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/presentation/commands/create/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use std::path::Path;
use std::sync::{Arc, Mutex};

use crate::presentation::cli::commands::CreateAction;
use crate::presentation::input::cli::commands::CreateAction;
use crate::presentation::user_output::UserOutput;

use super::errors::CreateSubcommandError;
Expand Down
2 changes: 1 addition & 1 deletion src/presentation/commands/create/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! ```rust,no_run
//! use std::path::{Path, PathBuf};
//! use std::sync::{Arc, Mutex};
//! use torrust_tracker_deployer_lib::presentation::cli::commands::CreateAction;
//! use torrust_tracker_deployer_lib::presentation::input::cli::commands::CreateAction;
//! use torrust_tracker_deployer_lib::presentation::commands::create;
//! use torrust_tracker_deployer_lib::presentation::user_output::{UserOutput, VerbosityLevel};
//!
Expand Down
2 changes: 1 addition & 1 deletion src/presentation/commands/create/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
//! This module tests the complete create command workflow including
//! configuration loading, validation, and command execution.

use crate::presentation::cli::CreateAction;
use crate::presentation::commands::create;
use crate::presentation::commands::tests::{
create_config_with_invalid_name, create_config_with_missing_keys, create_invalid_json_config,
create_valid_config, TestContext,
};
use crate::presentation::input::cli::CreateAction;
use crate::presentation::user_output::test_support::TestUserOutput;
use crate::presentation::user_output::VerbosityLevel;

Expand Down
2 changes: 1 addition & 1 deletion src/presentation/commands/create/tests/template.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Integration Tests for Template Generation

use crate::presentation::cli::CreateAction;
use crate::presentation::commands::create;
use crate::presentation::commands::tests::TestContext;
use crate::presentation::input::cli::CreateAction;
use crate::presentation::user_output::test_support::TestUserOutput;
use crate::presentation::user_output::VerbosityLevel;

Expand Down
6 changes: 3 additions & 3 deletions src/presentation/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use std::sync::{Arc, Mutex};

use crate::presentation::cli::Commands;
use crate::presentation::errors::CommandError;
use crate::presentation::input::cli::Commands;
use crate::presentation::user_output::UserOutput;

// Re-export command modules
Expand Down Expand Up @@ -51,7 +51,7 @@ pub mod tests;
///
/// ```rust
/// use clap::Parser;
/// use torrust_tracker_deployer_lib::presentation::{cli, commands, user_output};
/// use torrust_tracker_deployer_lib::presentation::{input::cli, commands, user_output};
/// use std::{path::Path, sync::{Arc, Mutex}};
///
/// let cli = cli::Cli::parse();
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn execute(
///
/// ```rust
/// use clap::Parser;
/// use torrust_tracker_deployer_lib::presentation::{commands, cli, errors, user_output};
/// use torrust_tracker_deployer_lib::presentation::{commands, input::cli, errors, user_output};
/// use torrust_tracker_deployer_lib::presentation::commands::destroy::DestroySubcommandError;
/// use torrust_tracker_deployer_lib::domain::environment::name::EnvironmentNameError;
/// use std::sync::{Arc, Mutex};
Expand Down
2 changes: 1 addition & 1 deletion src/presentation/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CommandError {
///
/// ```rust
/// use clap::Parser;
/// use torrust_tracker_deployer_lib::presentation::{cli, errors};
/// use torrust_tracker_deployer_lib::presentation::{input::cli, errors};
/// use torrust_tracker_deployer_lib::presentation::commands::destroy::DestroySubcommandError;
/// use torrust_tracker_deployer_lib::application::command_handlers::destroy::DestroyCommandHandlerError;
/// use std::path::PathBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl GlobalArgs {
/// # Example
///
/// ```rust
/// # use torrust_tracker_deployer_lib::presentation::cli::args::GlobalArgs;
/// # use torrust_tracker_deployer_lib::presentation::input::cli::args::GlobalArgs;
/// # use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig};
/// # use std::path::PathBuf;
/// // Create args with log configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ mod tests {
assert!(cli.command.is_some());
match cli.command.unwrap() {
Commands::Create { action } => match action {
crate::presentation::cli::CreateAction::Environment { env_file } => {
crate::presentation::input::cli::CreateAction::Environment { env_file } => {
assert_eq!(env_file, std::path::PathBuf::from("config.json"));
}
crate::presentation::cli::CreateAction::Template { .. } => {
crate::presentation::input::cli::CreateAction::Template { .. } => {
panic!("Expected Environment action")
}
},
Expand All @@ -205,10 +205,10 @@ mod tests {

match cli.command.unwrap() {
Commands::Create { action } => match action {
crate::presentation::cli::CreateAction::Environment { env_file } => {
crate::presentation::input::cli::CreateAction::Environment { env_file } => {
assert_eq!(env_file, std::path::PathBuf::from("env.json"));
}
crate::presentation::cli::CreateAction::Template { .. } => {
crate::presentation::input::cli::CreateAction::Template { .. } => {
panic!("Expected Environment action")
}
},
Expand Down Expand Up @@ -250,10 +250,10 @@ mod tests {

match cli.command.unwrap() {
Commands::Create { action } => match action {
crate::presentation::cli::CreateAction::Environment { env_file } => {
crate::presentation::input::cli::CreateAction::Environment { env_file } => {
assert_eq!(env_file, std::path::PathBuf::from("config.json"));
}
crate::presentation::cli::CreateAction::Template { .. } => {
crate::presentation::input::cli::CreateAction::Template { .. } => {
panic!("Expected Environment action")
}
},
Expand Down Expand Up @@ -298,10 +298,10 @@ mod tests {

match cli.command.unwrap() {
Commands::Create { action } => match action {
crate::presentation::cli::CreateAction::Template { output_path } => {
crate::presentation::input::cli::CreateAction::Template { output_path } => {
assert!(output_path.is_none());
}
crate::presentation::cli::CreateAction::Environment { .. } => {
crate::presentation::input::cli::CreateAction::Environment { .. } => {
panic!("Expected Template action")
}
},
Expand All @@ -321,13 +321,13 @@ mod tests {

match cli.command.unwrap() {
Commands::Create { action } => match action {
crate::presentation::cli::CreateAction::Template { output_path } => {
crate::presentation::input::cli::CreateAction::Template { output_path } => {
assert_eq!(
output_path,
Some(std::path::PathBuf::from("./config/my-env.json"))
);
}
crate::presentation::cli::CreateAction::Environment { .. } => {
crate::presentation::input::cli::CreateAction::Environment { .. } => {
panic!("Expected Template action")
}
},
Expand Down
65 changes: 65 additions & 0 deletions src/presentation/input/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Input Layer - Presentation Layer Component
//!
//! The Input Layer is responsible for parsing and validating user input from various sources,
//! primarily the command-line interface. This is the first layer in the presentation layer's
//! four-layer architecture: Input β†’ Dispatch β†’ Controllers β†’ Views.
//!
//! ## Purpose
//!
//! The Input Layer establishes a clear separation between:
//! - **Raw user input** (command-line arguments, configuration files)
//! - **Validated input data** ready for command dispatch
//! - **Command execution logic** (handled by other presentation layers)
//!
//! This separation provides several benefits:
//! - **Single Responsibility**: Input parsing is isolated from command execution
//! - **Testability**: Input validation can be tested independently
//! - **Flexibility**: Easy to add new input sources (web UI, API, config files)
//! - **Error Handling**: Input validation errors are handled at the appropriate layer
//!
//! ## Module Structure
//!
//! ```text
//! input/
//! β”œβ”€β”€ mod.rs # This file - layer exports and documentation
//! └── cli/ # Command-line interface parsing (moved from presentation/cli)
//! β”œβ”€β”€ mod.rs # Main CLI structure and parsing logic
//! β”œβ”€β”€ args.rs # Global CLI arguments (logging config)
//! └── commands.rs # Subcommand definitions
//! ```
//!
//! ## Design Principles
//!
//! - **Parse, Don't Execute**: This layer only parses and validates input
//! - **Early Validation**: Catch input errors as soon as possible
//! - **Clean Data Structures**: Provide well-typed data to subsequent layers
//! - **User-Friendly Errors**: Generate helpful error messages for invalid input
//!
//! ## Integration with Presentation Layer
//!
//! The Input Layer integrates with the broader presentation layer architecture:
//!
//! 1. **Input Layer** (this module) - Parses user input
//! 2. **Dispatch Layer** (`commands/mod.rs`) - Routes commands to handlers
//! 3. **Controller Layer** (`commands/*/handler.rs`) - Executes command logic
//! 4. **View Layer** (`user_output/`, `progress.rs`) - Presents results to users
//!
//! ## Future Enhancements
//!
//! As part of the presentation layer reorganization (Issue #154), this Input Layer
//! will serve as the foundation for:
//! - Configuration file input parsing
//! - Environment variable input handling
//! - Potential future input sources (API, web interface)
//!
//! ## Related Documentation
//!
//! - [Presentation Layer Reorganization Plan](../../docs/refactors/plans/presentation-layer-reorganization.md)
//! - [DDD Layer Placement Guide](../../docs/contributing/ddd-layer-placement.md)
//! - [Module Organization](../../docs/contributing/module-organization.md)

// CLI input parsing module
pub mod cli;

// Re-export CLI types for convenience
pub use cli::{Cli, Commands, GlobalArgs};
13 changes: 7 additions & 6 deletions src/presentation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
//!
//! ```text
//! presentation/
//! β”œβ”€β”€ cli/ # CLI argument parsing and structure
//! β”‚ β”œβ”€β”€ args.rs # Global CLI arguments (logging config)
//! β”‚ β”œβ”€β”€ commands.rs # Subcommand definitions
//! β”‚ └── mod.rs # Main Cli struct and parsing logic
//! β”œβ”€β”€ input/ # Input Layer - Input parsing and validation
//! β”‚ └── cli/ # CLI argument parsing and structure
//! β”‚ β”œβ”€β”€ args.rs # Global CLI arguments (logging config)
//! β”‚ β”œβ”€β”€ commands.rs # Subcommand definitions
//! β”‚ └── mod.rs # Main Cli struct and parsing logic
//! β”œβ”€β”€ commands/ # Command execution handlers
//! β”‚ β”œβ”€β”€ destroy.rs # Destroy command handler
//! β”‚ └── mod.rs # Unified command dispatch and error handling
Expand All @@ -38,17 +39,17 @@
//! ```

// Core presentation modules
pub mod cli;
pub mod commands;
pub mod errors;
pub mod input;
pub mod progress;
pub mod user_output;

// Re-export commonly used presentation types for convenience
pub use cli::{Cli, Commands, GlobalArgs};
pub use commands::create::CreateSubcommandError;
pub use commands::destroy::DestroySubcommandError;
pub use commands::{execute, handle_error};
pub use errors::CommandError;
pub use input::{Cli, Commands, GlobalArgs};
pub use progress::ProgressReporter;
pub use user_output::{Theme, UserOutput, VerbosityLevel};
Loading