1#![deny(warnings, clippy::todo, clippy::unimplemented)]
14
15pub(crate) mod cmd;
16pub(crate) mod interactive;
17pub(crate) mod patch;
18
19pub(crate) mod utils;
20
21pub use crate::cmd::*;
22pub use crate::patch::{AreaRule, DecodeBy, EncodeBy, FilePath, Patch, PatchFile, Replacer};
23pub use crate::utils::RegexIR;
24
25#[cfg(feature = "generate-examples")]
26pub use crate::patch::generate_examples;
27
28pub fn cli_exec(args: crate::cmd::Cli) -> anyhow::Result<()> {
29 match args.r#type {
30 SmartPatcherExecType::Apply(params) => {
31 let file = std::fs::File::open(params.patch)?;
32 let buf = std::io::BufReader::new(file);
33 let patches: PatchFile = serde_json::from_reader(buf)?;
34
35 let times = patches.patch(¶ms.work_at, ¶ms.work_at)?;
36 println!("Patch applied {times} time(s).");
37 }
38 SmartPatcherExecType::Test(params) => {
39 let file = std::fs::File::open(params.patch)?;
40 let buf = std::io::BufReader::new(file);
41 let patches: PatchFile = serde_json::from_reader(buf)?;
42
43 let times = patches.test(¶ms.work_at, ¶ms.work_at)?;
44 println!("Patch will be applied {times} time(s).");
45 }
46 #[cfg(feature = "generate-examples")]
47 SmartPatcherExecType::GenerateExamples => {
48 generate_examples()?;
49 }
50 }
51
52 Ok(())
53}