smart-patcher 0.7.0

Patcher based on rules
Documentation
//! Patcher based on rules.
//!
//! Main features:
//!
//! - `check` command to test patch (featured by `tests`, enabled by default)
//! - rules to select files and patch areas
//! - file content encoders/decoders support
//! - regex support
//! - Python, Lua and Rhai scripts support (featured by `python`, `lua` and `rhai`)
//!
//! See [`PatchFile`] for further details.

#![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(&params.work_at, &params.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(&params.work_at, &params.work_at)?;
      println!("Patch will be applied {times} time(s).");
    }
    #[cfg(feature = "generate-examples")]
    SmartPatcherExecType::GenerateExamples => {
      generate_examples()?;
    }
  }

  Ok(())
}