use std::path::PathBuf;
use anyhow::Result;
use colored::Colorize;
#[derive(clap::Parser, Debug)]
pub struct DeltaCommand {
pub old: PathBuf,
pub new: PathBuf,
#[arg(long, short = 'o')]
pub output: Option<PathBuf>,
#[arg(long)]
pub sign: Option<String>
}
pub fn run(cmd: &DeltaCommand) -> Result<()> {
let output = cmd
.output
.clone()
.unwrap_or_else(|| default_output(&cmd.new));
crate::pkg::delta::create_zpa_delta(
&cmd.old,
&cmd.new,
&output,
cmd.sign.as_deref()
)?;
println!(
"{} Apply it with 'zoi package install --apply-delta' or distribute \
it alongside the release.",
"::".bold().blue()
);
Ok(())
}
fn default_output(new_archive: &std::path::Path) -> PathBuf {
let stem = new_archive.file_name().map_or_else(
|| "package.zpa".to_string(),
|f| f.to_string_lossy().to_string()
);
new_archive.with_file_name(format!("{stem}.zdelta"))
}