Skip to main content

xbp_cli/commands/
deploy.rs

1//! Legacy local project deploy helpers (deprecated).
2//!
3//! Canonical release orchestration is `xbp deploy <target>` via `deploy_engine`.
4//! This module remains for any external library callers that still use
5//! auto-detect + local process start.
6
7use crate::strategies::{DeploymentConfig, DeploymentExecutor};
8use std::path::PathBuf;
9use tracing::debug;
10
11/// Execute advanced deployment with automatic project detection.
12///
13/// Deprecated: prefer `xbp deploy <target>` / `crate::commands::run_deploy`.
14#[deprecated(
15    note = "use xbp deploy <target> (deploy_engine::run_deploy) for service-first deploy"
16)]
17pub async fn deploy_application(
18    app_name: Option<String>,
19    port: Option<u16>,
20    app_dir: Option<PathBuf>,
21    config_path: Option<PathBuf>,
22    debug: bool,
23) -> Result<(), String> {
24    if debug {
25        debug!("Starting advanced deployment...");
26        debug!("App name: {:#?}", app_name);
27        debug!("Port: {:#?}", port);
28        debug!("App dir: {:#?}", app_dir);
29        debug!("Config path: {:#?}", config_path);
30    }
31
32    let config: DeploymentConfig =
33        DeploymentConfig::from_args_or_config(app_name, port, app_dir, config_path).await?;
34
35    if debug {
36        debug!("Final deployment config:");
37        debug!("  App name: {:#?}", config.app_name);
38        debug!("  Port: {:#?}", config.port);
39        debug!("  App dir: {:#?}", config.app_dir.display());
40        debug!("  Build command: {:#?}", config.build_command);
41        debug!("  Start command: {:#?}", config.start_command);
42        debug!("  Install command: {:#?}", config.install_command);
43    }
44
45    // Create and execute deployment
46    let mut executor: DeploymentExecutor = DeploymentExecutor::new(config, debug);
47    executor.deploy().await?;
48
49    Ok(())
50}
51
52/// Parse CLI arguments for the deploy command
53pub fn parse_deploy_args(
54    args: &[String],
55) -> (
56    Option<String>,
57    Option<u16>,
58    Option<PathBuf>,
59    Option<PathBuf>,
60) {
61    let mut app_name: Option<String> = None;
62    let mut port: Option<u16> = None;
63    let mut app_dir: Option<PathBuf> = None;
64    let mut config_path: Option<PathBuf> = None;
65
66    let mut i: usize = 0;
67    while i < args.len() {
68        match args[i].as_str() {
69            "--app-name" if i + 1 < args.len() => {
70                app_name = Some(args[i + 1].clone());
71                i += 2;
72            }
73            "--port" if i + 1 < args.len() => {
74                if let Ok(p) = args[i + 1].parse::<u16>() {
75                    port = Some(p);
76                }
77                i += 2;
78            }
79            "--app-dir" if i + 1 < args.len() => {
80                app_dir = Some(PathBuf::from(&args[i + 1]));
81                i += 2;
82            }
83            "--config" if i + 1 < args.len() => {
84                config_path = Some(PathBuf::from(&args[i + 1]));
85                i += 2;
86            }
87            "--app-name" | "--port" | "--app-dir" | "--config" => {
88                i += 1;
89            }
90            _ => {
91                i += 1;
92            }
93        }
94    }
95
96    (app_name, port, app_dir, config_path)
97}