pitchfork-cli 2.6.0

Daemons with DX
Documentation
use crate::Result;
use clap::Parser;

mod activate;
mod boot;
mod cd;
mod clean;
mod completion;
mod config;
mod disable;
mod enable;
mod list;
pub mod logs;
mod mcp;
mod proxy;
mod restart;
mod run;
mod schema;
mod start;
mod status;
mod stop;
mod supervisor;
mod tui;
mod usage;
mod wait;

#[derive(Debug, clap::Parser)]
#[clap(name = "pitchfork", version = env!("CARGO_PKG_VERSION"), about = env!("CARGO_PKG_DESCRIPTION"))]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(Debug, clap::Subcommand)]
#[allow(clippy::large_enum_variant)]
enum Commands {
    Activate(activate::Activate),
    Boot(boot::Boot),
    Cd(cd::Cd),
    Clean(clean::Clean),
    Config(config::Config),
    Completion(completion::Completion),
    Disable(disable::Disable),
    Enable(enable::Enable),
    List(list::List),
    Logs(logs::Logs),
    Mcp(mcp::Mcp),
    Proxy(proxy::Proxy),
    Restart(restart::Restart),
    Run(run::Run),
    Schema(schema::Schema),
    Start(start::Start),
    Status(status::Status),
    Stop(stop::Stop),
    Supervisor(supervisor::Supervisor),
    Tui(tui::Tui),
    Usage(usage::Usage),
    Wait(wait::Wait),
}

pub async fn run() -> Result<()> {
    let args = Cli::parse();
    match args.command {
        Commands::Activate(activate) => activate.run().await,
        Commands::Boot(boot) => boot.run().await,
        Commands::Cd(cd) => cd.run().await,
        Commands::Clean(clean) => clean.run().await,
        Commands::Config(config) => config.run().await,
        Commands::Completion(completion) => completion.run().await,
        Commands::Disable(disable) => disable.run().await,
        Commands::Enable(enable) => enable.run().await,
        Commands::List(list) => list.run().await,
        Commands::Logs(logs) => logs.run().await,
        Commands::Mcp(mcp) => mcp.run().await,
        Commands::Proxy(proxy) => proxy.run().await,
        Commands::Restart(restart) => restart.run().await,
        Commands::Run(run) => run.run().await,
        Commands::Schema(schema) => schema.run().await,
        Commands::Start(start) => start.run().await,
        Commands::Status(status) => status.run().await,
        Commands::Stop(stop) => stop.run().await,
        Commands::Supervisor(supervisor) => supervisor.run().await,
        Commands::Tui(tui) => tui.run().await,
        Commands::Usage(usage) => usage.run().await,
        Commands::Wait(wait) => wait.run().await,
    }
}

/// Drain and display any pending notifications from the supervisor.
///
/// Notifications are queued by the supervisor for events that happen
/// asynchronously (e.g. proxy bind failure) and would otherwise be invisible
/// to CLI users.  Call this at the end of user-facing commands that connect
/// to the supervisor via IPC.
pub(crate) async fn drain_notifications(ipc: &crate::ipc::client::IpcClient) {
    use log::LevelFilter;
    if let Ok(notifications) = ipc.get_notifications().await {
        for (level, msg) in notifications {
            match level {
                LevelFilter::Trace => trace!("{msg}"),
                LevelFilter::Debug => debug!("{msg}"),
                LevelFilter::Info => info!("{msg}"),
                LevelFilter::Warn => warn!("{msg}"),
                LevelFilter::Error => error!("{msg}"),
                _ => {}
            }
        }
    }
}