-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrouter.rs
More file actions
62 lines (58 loc) · 2.15 KB
/
Copy pathrouter.rs
File metadata and controls
62 lines (58 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Create Command Router
//!
//! This module handles the create command execution at the presentation layer,
//! routing between different subcommands (environment creation or template generation).
use std::path::Path;
use crate::presentation::dispatch::ExecutionContext;
use crate::presentation::input::cli::commands::CreateAction;
use super::errors::CreateCommandError;
/// Route the create command to its appropriate subcommand
///
/// This function routes between different create subcommands (environment, template, or schema).
///
/// # Arguments
///
/// * `action` - The create action to perform (environment creation, template generation, or schema generation)
/// * `working_dir` - Root directory for environment data storage
/// * `context` - Execution context providing access to application services
///
/// # Returns
///
/// Returns `Ok(())` on success, or a `CreateCommandError` on failure.
///
/// # Errors
///
/// Returns an error if the subcommand execution fails.
#[allow(clippy::result_large_err)] // Error contains detailed context for user guidance
pub async fn route_command(
action: CreateAction,
working_dir: &Path,
context: &ExecutionContext,
) -> Result<(), CreateCommandError> {
match action {
CreateAction::Environment { env_file } => context
.container()
.create_environment_controller()
.execute(&env_file, working_dir)
.await
.map(|_| ()) // Convert Environment<Created> to ()
.map_err(CreateCommandError::Environment),
CreateAction::Template {
output_path,
provider,
} => {
let template_path = output_path.unwrap_or_else(CreateAction::default_template_path);
context
.container()
.create_template_controller()
.execute(&template_path, provider)
.await
.map_err(CreateCommandError::Template)
}
CreateAction::Schema { output_path } => context
.container()
.create_schema_controller()
.execute(output_path.as_ref())
.map_err(CreateCommandError::Schema),
}
}