use anyhow::Result;
use clap::{Args, Parser, Subcommand};
use std::path::PathBuf;
pub mod buckify;
pub mod config_check;
pub mod debug;
pub mod fixups;
pub mod init;
pub mod stub;
pub mod vendor;
#[derive(Parser, Debug)]
#[command(
name = "muntjac",
version,
about = "Translate uv.lock into Buck2 build rules",
long_about = None,
)]
pub struct Cli {
#[command(flatten)]
pub globals: Globals,
#[command(subcommand)]
pub command: Command,
}
#[derive(Args, Debug, Clone)]
pub struct Globals {
#[arg(short = 'C', long = "cd", global = true, value_name = "PATH")]
pub cd: Option<PathBuf>,
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(long, global = true)]
pub no_network: bool,
#[arg(long, global = true)]
pub frozen: bool,
#[arg(long, global = true, value_name = "NAME")]
pub tree: Option<String>,
}
impl Globals {
pub fn workdir(&self) -> std::io::Result<PathBuf> {
match &self.cd {
Some(p) => std::fs::canonicalize(p),
None => std::env::current_dir(),
}
}
}
#[derive(Subcommand, Debug)]
pub enum Command {
Init(init::InitArgs),
Config {
#[command(subcommand)]
op: ConfigOp,
},
#[command(hide = true)]
Debug {
#[command(subcommand)]
op: Option<debug::DebugOp>,
},
Vendor,
Buckify,
Audit,
Fixups {
#[command(subcommand)]
op: fixups::FixupsOp,
},
Unused,
}
#[derive(Subcommand, Debug)]
pub enum ConfigOp {
Check(config_check::ConfigCheckArgs),
}
pub fn run(cli: Cli) -> Result<()> {
match cli.command {
Command::Init(args) => init::run(args, &cli.globals),
Command::Config {
op: ConfigOp::Check(args),
} => config_check::run(args, &cli.globals),
Command::Debug { op } => debug::run(op, &cli.globals),
Command::Vendor => vendor::run(&cli.globals),
Command::Buckify => buckify::run(&cli.globals),
Command::Audit => stub::run("audit", "S10"),
Command::Fixups { op } => fixups::run(op, &cli.globals),
Command::Unused => stub::run("unused", "S10"),
}
}