use clap::{Parser, Subcommand};
use std::path::PathBuf;
mod commands;
#[derive(Parser)]
#[command(
name = "pgn",
about = "Pidgin — A compact agent handoff protocol runtime",
version
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Parse {
file: PathBuf,
#[arg(long)]
json: bool,
},
Validate {
#[arg(required = true)]
files: Vec<PathBuf>,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
json: bool,
},
Check {
file: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
json: bool,
},
Resolve {
file: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
json: bool,
},
Expand {
file: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
r#out: Option<PathBuf>,
#[arg(long)]
json: bool,
},
ContextPlan {
file: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
json: bool,
},
Measure {
file: PathBuf,
#[arg(long)]
json: bool,
},
Run {
file: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
out: Option<PathBuf>,
},
Watch {
#[arg(default_value = ".")]
folder: PathBuf,
#[arg(long, default_value = ".")]
host: PathBuf,
},
Doctor {
#[arg(long, default_value = ".")]
host: PathBuf,
},
Init {
#[arg(long, default_value = ".")]
host: PathBuf,
#[arg(long)]
force: bool,
},
Docs,
#[cfg(feature = "server")]
Serve {
#[arg(long, default_value = "0.0.0.0:3847")]
bind: std::net::SocketAddr,
#[arg(long, default_value = ".")]
host: PathBuf,
},
}
#[cfg(feature = "server")]
#[tokio::main]
async fn main() {
run().await;
}
#[cfg(not(feature = "server"))]
fn main() {
run();
}
#[cfg(feature = "server")]
async fn run() {
let cli = Cli::parse();
match cli.command {
Commands::Parse { file, json } => commands::parse::run(file, json),
Commands::Validate { files, host, json } => commands::validate::run(files, host, json),
Commands::Check { file, host, json } => commands::check::run(file, host, json),
Commands::Resolve { file, host, json } => commands::resolve::run(file, host, json),
Commands::Expand {
file,
host,
r#out,
json,
} => commands::expand::run(file, host, r#out, json),
Commands::ContextPlan { file, host, json } => commands::context_plan::run(file, host, json),
Commands::Measure { file, json } => commands::measure::run(file, json),
Commands::Run { file, host, out } => commands::run::run(file, host, out),
Commands::Watch { folder, host } => commands::watch::run(folder, host),
Commands::Doctor { host } => commands::doctor::run(host),
Commands::Init { host, force } => commands::init::run(host, force),
Commands::Docs => commands::docs::run(),
#[cfg(feature = "server")]
Commands::Serve { bind, host } => commands::serve::run(bind, host).await,
}
}
#[cfg(not(feature = "server"))]
fn run() {
let cli = Cli::parse();
match cli.command {
Commands::Parse { file, json } => commands::parse::run(file, json),
Commands::Validate { files, host, json } => commands::validate::run(files, host, json),
Commands::Check { file, host, json } => commands::check::run(file, host, json),
Commands::Resolve { file, host, json } => commands::resolve::run(file, host, json),
Commands::Expand {
file,
host,
r#out,
json,
} => commands::expand::run(file, host, r#out, json),
Commands::ContextPlan { file, host, json } => commands::context_plan::run(file, host, json),
Commands::Measure { file, json } => commands::measure::run(file, json),
Commands::Run { file, host, out } => commands::run::run(file, host, out),
Commands::Watch { folder, host } => commands::watch::run(folder, host),
Commands::Doctor { host } => commands::doctor::run(host),
Commands::Init { host, force } => commands::init::run(host, force),
Commands::Docs => commands::docs::run(),
}
}