xbp 0.9.3

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
//! Advanced deployment command module
//!
//! This module provides an intelligent deployment system that automatically
//! detects project types and configures deployment strategies accordingly.

use tracing::debug;
use crate::strategies::{DeploymentConfig, DeploymentExecutor};
use std::path::PathBuf;

/// 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::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)
}