mod args;
mod banner;
mod bench;
mod build;
mod check;
mod daemon;
mod manifold;
mod passthrough;
mod registry;
mod repl;
mod run;
mod script;
mod shim;
mod style;
mod thrust;
mod version;
mod worker;
use anyhow::Result;
use clap::Parser;
pub use args::{Cli, Cmd, parse_mode};
pub use build::build_afterburner;
pub use manifold::{build_manifold, has_wildcard, is_implicit_open, parse_allow_list};
pub fn run() -> Result<()> {
if matches!(
std::env::args().nth(1).as_deref(),
Some("--help" | "-h" | "help")
) {
style::banner(env!("CARGO_PKG_VERSION"));
}
let cli = Cli::parse();
dispatch(cli)
}
pub fn report_error(e: &anyhow::Error) {
eprintln!(
"{} {}",
style::error_prefix(),
style::humanize_error(&format!("{e:#}"))
);
}
fn dispatch(mut cli: Cli) -> Result<()> {
if let Some(ref file) = cli.file {
match passthrough::detect(file) {
passthrough::Detected::KnownTarget(target) => {
return passthrough::dispatch(&mut cli, &target);
}
passthrough::Detected::PathTarget(target) if cli.eval_code.is_none() => {
return passthrough::dispatch(&mut cli, &target);
}
passthrough::Detected::Unknown(name)
if cli.eval_code.is_none() && cli.command.is_none() =>
{
anyhow::bail!("burn: unknown command '{name}'");
}
_ => {}
}
}
if cli.command.is_some()
&& cli.eval_code.is_none()
&& let Some(file) = cli.file.clone()
{
let rest_args = run::script_args_from_argv(&file);
banner::maybe_show(&cli);
return run::run_file(&cli, &file, &rest_args);
}
if let Some(code) = cli.eval_code.clone() {
let rest = if cli.command.is_some() {
run::eval_args_from_argv(&code)
} else {
let mut rest = Vec::new();
if let Some(f) = cli.file.take() {
rest.push(f.to_string_lossy().into_owned());
}
rest.extend(std::mem::take(&mut cli.rest_args));
rest
};
cli.file = None;
cli.command = None;
banner::maybe_show(&cli);
return run::run_source(&cli, &code, &rest);
}
let cmd = match cli.command.take() {
Some(c) => c,
None => {
if let Some(file) = cli.file.clone() {
Cmd::Run {
file: Some(file),
rest_args: std::mem::take(&mut cli.rest_args),
}
} else {
Cmd::Repl
}
}
};
if matches!(
cmd,
Cmd::Run { .. } | Cmd::Eval { .. } | Cmd::Thrust { .. } | Cmd::Bench { .. } | Cmd::Repl
) {
banner::maybe_show(&cli);
}
match cmd {
Cmd::Run { file, rest_args } => run::run_package_or_file(&cli, file.as_deref(), &rest_args),
Cmd::Eval { code, rest_args } => run::run_source(&cli, &code, &rest_args),
Cmd::Thrust { file } => thrust::thrust_from_stdin(&cli, &file),
Cmd::Check { file } => check::check_file(&cli, &file),
Cmd::Bench {
file,
iters,
workers,
} => bench::bench(&cli, &file, iters, workers),
Cmd::Repl => repl::repl(&cli),
Cmd::Version => version::print_version(),
Cmd::Login { token, registry } => registry::login(token.as_deref(), registry.as_deref()),
Cmd::Logout { registry } => registry::logout(registry.as_deref()),
Cmd::Whoami { registry } => registry::whoami(registry.as_deref()),
Cmd::New { spec, opts } => registry::new_package(&cli, &spec, &opts),
Cmd::Init { path, opts } => registry::init_package(&cli, path.as_deref(), &opts),
Cmd::Package { dir, out } => registry::package(dir.as_deref(), out.as_deref()),
Cmd::Test { dir } => registry::test(&cli, dir.as_deref()),
Cmd::Clean { dir, cache } => registry::clean(dir.as_deref(), cache),
Cmd::Publish {
afb,
dir,
registry: reg,
token,
} => registry::publish(
afb.as_deref(),
dir.as_deref(),
reg.as_deref(),
token.as_deref(),
),
Cmd::Yank {
pkg,
undo,
registry: reg,
token,
} => registry::yank(&pkg, undo, reg.as_deref(), token.as_deref()),
Cmd::Install {
pkg,
registry: reg,
jobs,
locked,
} => registry::install(pkg.as_deref(), reg.as_deref(), jobs, locked),
Cmd::Search {
query,
registry: reg,
} => registry::search(&query, reg.as_deref()),
Cmd::Add {
pkg,
dir,
registry: reg,
} => registry::add(&pkg, dir.as_deref(), reg.as_deref()),
Cmd::Info { pkg, registry: reg } => registry::info(&pkg, reg.as_deref()),
Cmd::Owner {
pkg,
list,
add,
remove,
} => registry::owner(pkg.as_deref(), list, add.as_deref(), remove.as_deref()),
}
}