xbp 10.32.0

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
//! Custom help renderer for interactive and bare `xbp` invocations.

use crate::cli::ui;
use crate::commands::service::{is_xbp_project, load_xbp_config};
use crate::strategies::get_all_services;
use colored::Colorize;

/// Print a stylized help banner and quick usage guide.
pub async fn print_help() {
    ui::configure_color_output();
    print_banner();

    ui::section("Usage");
    println!("  {}", "xbp <command> [options]".bright_white());

    print_command_groups().await;

    ui::section("Global flags");
    print_flag_line("--debug", "Enable verbose debugging output");
    print_flag_line("--help, -h", "Show this quick-start guide");
    print_flag_line("--commands", "List every command with descriptions");
    print_flag_line("--logs", "Open the logs directory");

    ui::section("Discover");
    print_example("xbp workers -h              Subcommand help and examples");
    print_example("xbp help workers            Same via clap help subcommand");
    print_example("xbp --commands              Full alphabetical command tree");

    ui::section("Examples");
    print_example("xbp diag");
    print_example("xbp workers list");
    print_example("xbp workers logs -f");
    print_example("xbp api health");
    print_example("xbp mcp serve --detach");
    print_example("xbp mcp config");
    print_example("xbp mcp inspector");
    print_example("xbp install docker");

    println!(
        "\n{} {}",
        "Docs".bright_blue().bold(),
        "https://github.com/xylex-group/xbp".cyan().underline()
    );
    println!();
}

fn print_banner() {
    println!();
    println!(
        "{}  {}",
        "XBP".bright_magenta().bold(),
        format!("v{}", env!("CARGO_PKG_VERSION")).bright_white()
    );
    println!("{}", "Deploy · operate · debug · ship".bright_black());
    ui::divider(44);
}

async fn print_command_groups() {
    ui::section("Essentials");
    print_command("diag", "System diagnostics and readiness checks");
    print_command("services", "List configured project services");
    print_command("service", "Build, install, start, or dev a service");
    print_command("workers", "Cloudflare Workers list, logs, deploy");
    print_command("api", "Control-plane health, projects, routes");
    print_command("mcp", "Built-in MCP server for AI agents");
    print_command("config", "Project and provider configuration");
    print_command("install", "Host packages and project tooling");

    ui::section("Deploy & release");
    print_command("redeploy", "Redeploy one service or the whole project");
    print_command("version", "Inspect, bump, and release versions");
    print_command("publish", "npm/crates publish workflows");
    print_command("commit", "Conventional git commits");
    print_command("logs", "Tail local or remote logs");

    ui::section("Cloud & network");
    print_command("dns", "DNS zones, records, DNSSEC, providers");
    print_command("domains", "Search and check registered domains");
    print_command("nginx", "Site configs and upstream mappings");
    print_command("network", "Floating IPs and host networking");
    print_command("cloudflared", "Cloudflare Tunnel TCP forwarders");
    print_command("ports", "Listening ports and exposure checks");

    ui::section("Remote & access");
    print_command("ssh", "Interactive remote shell over SSH");
    print_command("curl", "Fetch HTTP endpoints with sane defaults");
    print_command("login", "CLI session against the XBP dashboard");

    ui::section("Process manager");
    print_command("list", "List PM2 processes");
    print_command("start", "Start a binary under PM2");
    print_command("stop", "Stop PM2 processes");
    print_command("env", "Show PM2 environment for a process");

    ui::section("More");
    print_command("init", "Initialize an XBP project");
    print_command("setup", "Install common host dependencies");
    print_command("generate", "Generate config or systemd units");
    print_command("done", "Summarize git activity into Markdown");

    if is_xbp_project().await {
        ui::section("This project");
        println!("  {}", "services".bright_cyan());
        println!(
            "  {} {}",
            "service <cmd> <name>".bright_cyan(),
            "build · install · start · dev".bright_black()
        );

        if let Ok(config) = load_xbp_config().await {
            let services = get_all_services(&config);
            if !services.is_empty() {
                ui::section("Services here");
                for service in services.iter().take(6) {
                    println!(
                        "  {} {}:{}",
                        service.name.bright_green(),
                        service.target.dimmed(),
                        service.port.to_string().yellow()
                    );
                }
                if services.len() > 6 {
                    println!(
                        "  {} {} more",
                        "".dimmed(),
                        (services.len() - 6).to_string().dimmed()
                    );
                }
            }
        }
    }
}

fn print_command(name: &str, description: &str) {
    println!(
        "  {:<14} {}",
        name.bright_cyan().bold(),
        description.bright_black()
    );
}

fn print_flag_line(flag: &str, description: &str) {
    println!(
        "  {:<16} {}",
        flag.bright_yellow(),
        description.bright_black()
    );
}

fn print_example(command: &str) {
    println!("  {}", command.dimmed());
}