summaryrefslogtreecommitdiffstats
path: root/vendor/similar/examples/udiff.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/similar/examples/udiff.rs')
-rw-r--r--vendor/similar/examples/udiff.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/similar/examples/udiff.rs b/vendor/similar/examples/udiff.rs
new file mode 100644
index 0000000..3d8eb9c
--- /dev/null
+++ b/vendor/similar/examples/udiff.rs
@@ -0,0 +1,24 @@
+use std::fs::read;
+use std::io;
+use std::process::exit;
+
+use similar::TextDiff;
+
+fn main() {
+ let args: Vec<_> = std::env::args_os().collect();
+ if args.len() != 3 {
+ eprintln!("usage: udiff [old] [new]");
+ exit(1);
+ }
+
+ let old = read(&args[1]).unwrap();
+ let new = read(&args[2]).unwrap();
+ TextDiff::from_lines(&old, &new)
+ .unified_diff()
+ .header(
+ &args[1].as_os_str().to_string_lossy(),
+ &args[2].as_os_str().to_string_lossy(),
+ )
+ .to_writer(io::stdout())
+ .unwrap();
+}