summaryrefslogtreecommitdiffstats
path: root/vendor/similar/examples/udiff.rs
blob: 3d8eb9c9107ccd59bd2e58aebf7a943e073346a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
}