#![deny(warnings, clippy::todo, clippy::unimplemented)]
pub(crate) mod cmd;
pub(crate) mod interactive;
pub(crate) mod patch;
pub(crate) mod utils;
pub use crate::cmd::*;
pub use crate::patch::{AreaRule, DecodeBy, EncodeBy, FilePath, Patch, PatchFile, Replacer};
pub use crate::utils::RegexIR;
#[cfg(feature = "generate-examples")]
pub use crate::patch::generate_examples;
pub fn cli_exec(args: crate::cmd::Cli) -> anyhow::Result<()> {
match args.r#type {
SmartPatcherExecType::Apply(params) => {
let file = std::fs::File::open(params.patch)?;
let buf = std::io::BufReader::new(file);
let patches: PatchFile = serde_json::from_reader(buf)?;
let times = patches.patch(¶ms.work_at, ¶ms.work_at)?;
println!("Patch applied {times} time(s).");
}
SmartPatcherExecType::Test(params) => {
let file = std::fs::File::open(params.patch)?;
let buf = std::io::BufReader::new(file);
let patches: PatchFile = serde_json::from_reader(buf)?;
let times = patches.test(¶ms.work_at, ¶ms.work_at)?;
println!("Patch will be applied {times} time(s).");
}
#[cfg(feature = "generate-examples")]
SmartPatcherExecType::GenerateExamples => {
generate_examples()?;
}
}
Ok(())
}