]>
Commit | Line | Data |
---|---|---|
6a06907d XL |
1 | // Sample program. Do not use. |
2 | use std::env; | |
3 | use std::fs; | |
4 | use std::io::{self, Write}; | |
5 | use std::process; | |
6 | fn main() { | |
7 | let mut o = env::args_os(); | |
8 | // parse CLI | |
9 | let exe = match o.next() { | |
10 | Some(from) => from, | |
11 | None => { | |
12 | eprintln!("Usage: [exe] [from] [to]"); | |
13 | process::exit(1); | |
14 | } | |
15 | }; | |
16 | let from = match o.next() { | |
17 | Some(from) => from, | |
18 | None => { | |
19 | eprintln!("Usage: {} [from] [to]", exe.to_string_lossy()); | |
20 | process::exit(1); | |
21 | } | |
22 | }; | |
23 | let to = match o.next() { | |
24 | Some(from) => from, | |
25 | None => { | |
26 | eprintln!("Usage: {} [from] [to]", exe.to_string_lossy()); | |
27 | process::exit(1); | |
28 | } | |
29 | }; | |
30 | // read files | |
31 | let from_content = match fs::read(&from) { | |
32 | Ok(from_content) => from_content, | |
33 | Err(e) => { | |
34 | eprintln!("Failed to read from-file: {}", e); | |
35 | process::exit(2); | |
36 | } | |
37 | }; | |
38 | let to_content = match fs::read(&to) { | |
39 | Ok(to_content) => to_content, | |
40 | Err(e) => { | |
41 | eprintln!("Failed to read to-file: {}", e); | |
42 | process::exit(2); | |
43 | } | |
44 | }; | |
45 | // run diff | |
46 | io::stdout() | |
47 | .write_all(&unified_diff::diff( | |
48 | &from_content, | |
49 | &from.to_string_lossy(), | |
50 | &to_content, | |
51 | &to.to_string_lossy(), | |
52 | 1, | |
53 | )) | |
54 | .unwrap(); | |
55 | } |