-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.rs
More file actions
70 lines (62 loc) · 2.38 KB
/
app.rs
File metadata and controls
70 lines (62 loc) · 2.38 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
63
64
65
66
67
68
69
70
//! Main Application Bootstrap
//!
//! This module provides a thin bootstrap layer for the Torrust Tracker Deployer CLI.
//! It handles application initialization, logging setup, and command dispatch while
//! delegating all CLI parsing and business logic to the presentation layer.
//!
//! ## Responsibilities
//!
//! - **Application Lifecycle**: Initialize and shutdown the application
//! - **Logging Setup**: Configure logging based on CLI arguments
//! - **Command Dispatch**: Route commands to the presentation layer for execution
//! - **Exit Handling**: Manage application exit codes and cleanup
//!
//! ## Design Principles
//!
//! - **Thin Layer**: Minimal logic, maximum delegation to appropriate layers
//! - **Single Responsibility**: Focus only on application bootstrap concerns
//! - **Clean Separation**: No CLI parsing or business logic in this module
use clap::Parser;
use tracing::info;
use crate::{bootstrap, presentation};
/// Main application entry point
///
/// This function serves as the application bootstrap, handling:
/// 1. CLI argument parsing (delegated to presentation layer)
/// 2. Logging initialization using `LoggingConfig`
/// 3. Command execution (delegated to presentation layer)
/// 4. Error handling and exit code management
///
/// # Panics
///
/// This function will panic if:
/// - Log directory cannot be created (filesystem permissions issue)
/// - Logging initialization fails (usually means it was already initialized)
///
/// Both panics are intentional as logging is critical for observability.
pub fn run() {
let cli = presentation::Cli::parse();
let logging_config = cli.global.logging_config();
bootstrap::logging::init_subscriber(logging_config);
info!(
app = "torrust-tracker-deployer",
version = env!("CARGO_PKG_VERSION"),
log_dir = %cli.global.log_dir.display(),
log_file_format = ?cli.global.log_file_format,
log_stderr_format = ?cli.global.log_stderr_format,
log_output = ?cli.global.log_output,
"Application started"
);
match cli.command {
Some(command) => {
if let Err(e) = presentation::execute(command, &cli.global.working_dir) {
presentation::handle_error(&e);
std::process::exit(1);
}
}
None => {
bootstrap::help::display_getting_started();
}
}
info!("Application finished");
}