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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Advanced deployment command module
//!
//! This module provides an intelligent deployment system that automatically
//! detects project types and configures deployment strategies accordingly.
use crate::strategies::{DeploymentConfig, DeploymentExecutor};
use std::path::PathBuf;
use tracing::debug;
/// Execute advanced deployment with automatic project detection
///
/// # Arguments
///
/// * `app_name` - Optional application name (will be detected from project if not provided)
/// * `port` - Optional port number (will use default based on project type if not provided)
/// * `app_dir` - Optional application directory (defaults to current directory)
/// * `config_path` - Optional path to xbp.json configuration file
/// * `debug` - Whether to enable debug output
///
/// # Returns
///
/// * `Ok(())` if deployment was successful
/// * `Err(String)` if deployment failed
pub async fn deploy_application(
app_name: Option<String>,
port: Option<u16>,
app_dir: Option<PathBuf>,
config_path: Option<PathBuf>,
debug: bool,
) -> Result<(), String> {
if debug {
debug!("Starting advanced deployment...");
debug!("App name: {:#?}", app_name);
debug!("Port: {:#?}", port);
debug!("App dir: {:#?}", app_dir);
debug!("Config path: {:#?}", config_path);
}
let config: DeploymentConfig =
DeploymentConfig::from_args_or_config(app_name, port, app_dir, config_path).await?;
if debug {
debug!("Final deployment config:");
debug!(" App name: {:#?}", config.app_name);
debug!(" Port: {:#?}", config.port);
debug!(" App dir: {:#?}", config.app_dir.display());
debug!(" Build command: {:#?}", config.build_command);
debug!(" Start command: {:#?}", config.start_command);
debug!(" Install command: {:#?}", config.install_command);
}
// Create and execute deployment
let mut executor: DeploymentExecutor = DeploymentExecutor::new(config, debug);
executor.deploy().await?;
Ok(())
}
/// Parse CLI arguments for the deploy command
pub fn parse_deploy_args(
args: &[String],
) -> (
Option<String>,
Option<u16>,
Option<PathBuf>,
Option<PathBuf>,
) {
let mut app_name: Option<String> = None;
let mut port: Option<u16> = None;
let mut app_dir: Option<PathBuf> = None;
let mut config_path: Option<PathBuf> = None;
let mut i: usize = 0;
while i < args.len() {
match args[i].as_str() {
"--app-name" => {
if i + 1 < args.len() {
app_name = Some(args[i + 1].clone());
i += 2;
} else {
i += 1;
}
}
"--port" => {
if i + 1 < args.len() {
if let Ok(p) = args[i + 1].parse::<u16>() {
port = Some(p);
}
i += 2;
} else {
i += 1;
}
}
"--app-dir" => {
if i + 1 < args.len() {
app_dir = Some(PathBuf::from(&args[i + 1]));
i += 2;
} else {
i += 1;
}
}
"--config" => {
if i + 1 < args.len() {
config_path = Some(PathBuf::from(&args[i + 1]));
i += 2;
} else {
i += 1;
}
}
_ => {
i += 1;
}
}
}
(app_name, port, app_dir, config_path)
}