Skip to content

Commit

Permalink
allow diffing using myers with --myers in diff example
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshkukreti committed Feb 4, 2024
1 parent 10c9a13 commit eb843e5
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions examples/diff.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
extern crate diff;

fn main() {
let args = std::env::args().collect::<Vec<_>>();
let mut args = std::env::args().skip(1).collect::<Vec<_>>();

if args.len() != 3 {
println!("usage: cargo run --example diff <first file> <second file>");
let myers = args.iter().any(|arg| arg == "--myers");

args.retain(|arg| arg != "--myers");

if args.len() != 2 {
println!("usage: cargo run --example diff [--myers] <first file> <second file>");
std::process::exit(1);
}

let left = std::fs::read_to_string(&args[1]).unwrap();
let right = std::fs::read_to_string(&args[2]).unwrap();
let left = std::fs::read_to_string(&args[0]).unwrap();
let right = std::fs::read_to_string(&args[1]).unwrap();

let diff = if myers {
diff::myers::lines(&left, &right)
} else {
diff::lines(&left, &right)
};

for diff in diff::lines(&left, &right) {
match diff {
for d in diff {
match d {
diff::Result::Left(l) => println!("-{}", l),
diff::Result::Both(l, _) => println!(" {}", l),
diff::Result::Right(r) => println!("+{}", r),
Expand Down

0 comments on commit eb843e5

Please sign in to comment.