xbp 10.15.4

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
//! custom help renderer
//!
//! provides stylized help banner and custom guidance
//! detects xbp projects and shows service specific commands
//! displays available services when in an xbp project directory

use crate::commands::service::{is_xbp_project, load_xbp_config};
use crate::strategies::get_all_services;
use colored::Colorize;
use tracing::info;

/// Print a stylized help banner and quick usage guide.
pub async fn print_help() {
    println!("\nXBP - XYLEX BUILD PACK");
    println!("{}\n", "".repeat(60));

    println!("Usage: xbp <command> [options]");
    println!();

    println!("Commands:");
    println!("  ports      - List active ports and processes");
    println!("  setup      - Run initial setup");
    println!("  redeploy   - Redeploy services");
    println!("  config     - Show configuration");
    println!("  install    - Install packages");
    println!("  logs       - View logs");
    println!("  list       - List PM2 processes");
    println!("  start      - Start PM2 process");
    println!("  nginx      - Manage Nginx");
    println!("  diag       - Run diagnostics");
    println!("  monitor    - Monitor services");
    println!("  snapshot   - Save a PM2 restore snapshot");
    println!("  version    - Inspect and sync project versions");
    println!("  generate   - Generation commands");
    println!();

    info!("\n{}", "XBP - XYLEX BUILD PACK".bright_blue().bold());
    info!("{}\n", "".repeat(60).dimmed());

    info!(
        "{} {}",
        "Usage:".bright_blue(),
        "xbp <command> [options]".yellow()
    );
    info!("");

    info!("{}", "Commands:".bright_blue().bold());
    info!("  {} - List active ports and processes", "ports".cyan());
    info!("  {} - Run initial setup", "setup".cyan());
    info!("  {} - Redeploy services", "redeploy".cyan());
    info!("  {} - Show configuration", "config".cyan());
    info!("  {} - Install packages", "install".cyan());
    info!("  {} - View logs", "logs".cyan());
    info!("  {} - List PM2 processes", "list".cyan());
    info!("  {} - Start PM2 process", "start".cyan());
    info!("  {} - Manage Nginx", "nginx".cyan());
    info!("  {} - Run diagnostics", "diag".cyan());
    info!("  {} - Monitor services", "monitor".cyan());
    info!("  {} - Save a PM2 restore snapshot", "snapshot".cyan());
    info!("  {} - Inspect and sync project versions", "version".cyan());
    info!("");

    if is_xbp_project().await {
        println!("Service Commands:");
        println!("  services              - List all services");
        println!("  service <cmd> <name>  - Run service command");
        println!("    Commands: build, install, start, dev");
        println!();

        info!("{}", "Service Commands:".bright_blue().bold());
        info!("  {} - List all services", "services".cyan());
        info!("  {} - Run service command", "service <cmd> <name>".cyan());
        info!("    Commands: {}", "build, install, start, dev".yellow());
        info!("");

        if let Ok(config) = load_xbp_config().await {
            let services: Vec<crate::strategies::ServiceConfig> = get_all_services(&config);
            if !services.is_empty() {
                println!("Available Services:");
                for service in services.iter().take(5) {
                    println!("{} {}:{}", service.name, service.target, service.port);
                }
                if services.len() > 5 {
                    println!("  ...and {} more", services.len() - 5);
                }
                println!();

                info!("{}", "Available Services:".bright_green());
                for service in services.iter().take(5) {
                    info!(
                        "  • {} {}:{}",
                        service.name.bright_cyan(),
                        service.target.dimmed(),
                        service.port.to_string().yellow()
                    );
                }
                if services.len() > 5 {
                    info!(
                        "  {} {} more",
                        "...and".dimmed(),
                        (services.len() - 5).to_string().dimmed()
                    );
                }
                info!("");
            }
        }
    }

    println!("Options:");
    println!("  --debug  - Enable debug output");
    println!("  --help   - Show help message");
    println!("  --logs   - Open logs directory");
    println!();

    println!("Examples:");
    println!("  xbp ports -p 3000 --kill        - Kill processes on port 3000");
    println!("  xbp install docker              - Install Docker");
    println!("  xbp start \"npm start\" --name my-app - Start a process with PM2");
    println!("  xbp snapshot                    - Save the current PM2 state");
    println!("  xbp version                     - Show local and git versions");
    println!("  xbp version patch               - Bump the patch version locally");
    if is_xbp_project().await {
        println!("  xbp service build zeus          - Build a service");
        println!("  xbp redeploy zeus               - Redeploy a service");
    }
    println!();
    println!("For more information: https://github.com/xylex-group/xbp");

    info!("{}", "Options:".bright_blue().bold());
    info!("  {} - Enable debug output", "--debug".yellow());
    info!("  {} - Show help message", "--help".yellow());
    info!("  {} - Open logs directory", "--logs".yellow());
    info!("");

    info!("{}", "Examples:".bright_blue().bold());
    info!(
        "  {} - Kill processes on port 3000",
        "xbp ports -p 3000 --kill".dimmed()
    );
    info!("  {} - Install Docker", "xbp install docker".dimmed());
    info!(
        "  {} - Start a process with PM2",
        "xbp start \"npm start\" --name my-app".dimmed()
    );
    info!("  {} - Save the current PM2 state", "xbp snapshot".dimmed());
    info!("  {} - Show local and git versions", "xbp version".dimmed());
    info!(
        "  {} - Bump the patch version locally",
        "xbp version patch".dimmed()
    );
    if is_xbp_project().await {
        info!("  {} - Build a service", "xbp service build zeus".dimmed());
        info!("  {} - Redeploy a service", "xbp redeploy zeus".dimmed());
    }
    info!("");
    info!(
        "For more information: {}",
        "https://github.com/xylex-group/xbp".cyan()
    );
}