From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/prettydiff/src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 vendor/prettydiff/src/main.rs (limited to 'vendor/prettydiff/src/main.rs') diff --git a/vendor/prettydiff/src/main.rs b/vendor/prettydiff/src/main.rs new file mode 100644 index 000000000..9b6a59bbd --- /dev/null +++ b/vendor/prettydiff/src/main.rs @@ -0,0 +1,51 @@ +use std::fs::File; +use std::io::prelude::*; +use std::path::PathBuf; +use structopt::StructOpt; + +/// Side-by-side diff for two files +#[derive(StructOpt, Debug)] +#[structopt(name = "prettydiff")] +struct Opt { + /// Left file + #[structopt(name = "LEFT", parse(from_os_str))] + left: PathBuf, + /// Right file + #[structopt(name = "RIGHT", parse(from_os_str))] + right: PathBuf, + /// Don't show lines numbers + #[structopt(long = "disable_lines")] + disable_lines: bool, + /// Show non-changed blocks + #[structopt(long = "show_same")] + show_same: bool, + /// Align new lines inside change block + #[structopt(long = "disable_align")] + disable_align: bool, +} + +fn read_file(path: &PathBuf) -> std::io::Result { + let mut file = File::open(path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + Ok(contents) +} + +fn main() -> std::io::Result<()> { + let opt = Opt::from_args(); + + let left_data = read_file(&opt.left)?; + let left_name = opt.left.into_os_string().into_string().unwrap(); + + let right_data = read_file(&opt.right)?; + let right_name = opt.right.into_os_string().into_string().unwrap(); + + prettydiff::diff_lines(&left_data, &right_data) + .names(&left_name, &right_name) + .set_show_lines(!opt.disable_lines) + .set_diff_only(!opt.show_same) + .set_align_new_lines(!opt.disable_align) + .prettytable(); + + Ok(()) +} -- cgit v1.2.3