summaryrefslogtreecommitdiffstats
path: root/vendor/prettydiff/src/main.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/prettydiff/src/main.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/prettydiff/src/main.rs')
-rw-r--r--vendor/prettydiff/src/main.rs51
1 files changed, 51 insertions, 0 deletions
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<String> {
+ 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(())
+}