|
14 | 14 |
|
15 | 15 | #![deny(warnings)]
|
16 | 16 |
|
17 |
| -use docopt::Docopt; |
18 | 17 | use git2::{Diff, DiffOptions, Error, Object, ObjectType, Repository};
|
19 | 18 | use git2::{DiffFindOptions, DiffFormat};
|
20 |
| -use serde_derive::Deserialize; |
21 | 19 | use std::str;
|
| 20 | +use structopt::StructOpt; |
22 | 21 |
|
23 |
| -#[derive(Deserialize)] |
| 22 | +#[derive(StructOpt)] |
24 | 23 | #[allow(non_snake_case)]
|
25 | 24 | struct Args {
|
| 25 | + #[structopt(name = "from_oid")] |
26 | 26 | arg_from_oid: Option<String>,
|
| 27 | + #[structopt(name = "to_oid")] |
27 | 28 | arg_to_oid: Option<String>,
|
| 29 | + #[structopt(name = "patch", short, long)] |
| 30 | + /// show output in patch format |
28 | 31 | flag_patch: bool,
|
| 32 | + #[structopt(name = "cached", long)] |
| 33 | + /// use staged changes as diff |
29 | 34 | flag_cached: bool,
|
| 35 | + #[structopt(name = "nocached", long)] |
| 36 | + /// do not use staged changes |
30 | 37 | flag_nocached: bool,
|
| 38 | + #[structopt(name = "name-only", long)] |
| 39 | + /// show only names of changed files |
31 | 40 | flag_name_only: bool,
|
| 41 | + #[structopt(name = "name-status", long)] |
| 42 | + /// show only names and status changes |
32 | 43 | flag_name_status: bool,
|
| 44 | + #[structopt(name = "raw", long)] |
| 45 | + /// generate the raw format |
33 | 46 | flag_raw: bool,
|
| 47 | + #[structopt(name = "format", long)] |
| 48 | + /// specify format for stat summary |
34 | 49 | flag_format: Option<String>,
|
| 50 | + #[structopt(name = "color", long)] |
| 51 | + /// use color output |
35 | 52 | flag_color: bool,
|
| 53 | + #[structopt(name = "no-color", long)] |
| 54 | + /// never use color output |
36 | 55 | flag_no_color: bool,
|
| 56 | + #[structopt(short = "R")] |
| 57 | + /// swap two inputs |
37 | 58 | flag_R: bool,
|
| 59 | + #[structopt(name = "text", short = "a", long)] |
| 60 | + /// treat all files as text |
38 | 61 | flag_text: bool,
|
| 62 | + #[structopt(name = "ignore-space-at-eol", long)] |
| 63 | + /// ignore changes in whitespace at EOL |
39 | 64 | flag_ignore_space_at_eol: bool,
|
| 65 | + #[structopt(name = "ignore-space-change", short = "b", long)] |
| 66 | + /// ignore changes in amount of whitespace |
40 | 67 | flag_ignore_space_change: bool,
|
| 68 | + #[structopt(name = "ignore-all-space", short = "w", long)] |
| 69 | + /// ignore whitespace when comparing lines |
41 | 70 | flag_ignore_all_space: bool,
|
| 71 | + #[structopt(name = "ignored", long)] |
| 72 | + /// show untracked files |
42 | 73 | flag_ignored: bool,
|
| 74 | + #[structopt(name = "untracked", long)] |
| 75 | + /// generate diff using the patience algorithm |
43 | 76 | flag_untracked: bool,
|
| 77 | + #[structopt(name = "patience", long)] |
| 78 | + /// show ignored files as well |
44 | 79 | flag_patience: bool,
|
| 80 | + #[structopt(name = "minimal", long)] |
| 81 | + /// spend extra time to find smallest diff |
45 | 82 | flag_minimal: bool,
|
| 83 | + #[structopt(name = "stat", long)] |
| 84 | + /// generate a diffstat |
46 | 85 | flag_stat: bool,
|
| 86 | + #[structopt(name = "numstat", long)] |
| 87 | + /// similar to --stat, but more machine friendly |
47 | 88 | flag_numstat: bool,
|
| 89 | + #[structopt(name = "shortstat", long)] |
| 90 | + /// only output last line of --stat |
48 | 91 | flag_shortstat: bool,
|
| 92 | + #[structopt(name = "summary", long)] |
| 93 | + /// output condensed summary of header info |
49 | 94 | flag_summary: bool,
|
| 95 | + #[structopt(name = "find-renames", short = "M", long)] |
| 96 | + /// set threshold for findind renames (default 50) |
50 | 97 | flag_find_renames: Option<u16>,
|
| 98 | + #[structopt(name = "find-copies", short = "C", long)] |
| 99 | + /// set threshold for finding copies (default 50) |
51 | 100 | flag_find_copies: Option<u16>,
|
| 101 | + #[structopt(name = "find-copies-harder", long)] |
| 102 | + /// inspect unmodified files for sources of copies |
52 | 103 | flag_find_copies_harder: bool,
|
| 104 | + #[structopt(name = "break_rewrites", short = "B", long)] |
| 105 | + /// break complete rewrite changes into pairs |
53 | 106 | flag_break_rewrites: bool,
|
| 107 | + #[structopt(name = "unified", short = "U", long)] |
| 108 | + /// lints of context to show |
54 | 109 | flag_unified: Option<u32>,
|
| 110 | + #[structopt(name = "inter-hunk-context", long)] |
| 111 | + /// maximum lines of change between hunks |
55 | 112 | flag_inter_hunk_context: Option<u32>,
|
| 113 | + #[structopt(name = "abbrev", long)] |
| 114 | + /// length to abbreviate commits to |
56 | 115 | flag_abbrev: Option<u16>,
|
| 116 | + #[structopt(name = "src-prefix", long)] |
| 117 | + /// show given source prefix instead of 'a/' |
57 | 118 | flag_src_prefix: Option<String>,
|
| 119 | + #[structopt(name = "dst-prefix", long)] |
| 120 | + /// show given destinction prefix instead of 'b/' |
58 | 121 | flag_dst_prefix: Option<String>,
|
| 122 | + #[structopt(name = "path", long = "git-dir")] |
| 123 | + /// path to git repository to use |
59 | 124 | flag_git_dir: Option<String>,
|
60 | 125 | }
|
61 | 126 |
|
@@ -262,48 +327,7 @@ impl Args {
|
262 | 327 | }
|
263 | 328 |
|
264 | 329 | fn main() {
|
265 |
| - const USAGE: &str = " |
266 |
| -usage: diff [options] [<from-oid> [<to-oid>]] |
267 |
| -
|
268 |
| -Options: |
269 |
| - -p, --patch show output in patch format |
270 |
| - --cached use staged changes as diff |
271 |
| - --nocached do not use staged changes |
272 |
| - --name-only show only names of changed files |
273 |
| - --name-status show only names and status changes |
274 |
| - --raw generate the raw format |
275 |
| - --format=<format> specify format for stat summary |
276 |
| - --color use color output |
277 |
| - --no-color never use color output |
278 |
| - -R swap two inputs |
279 |
| - -a, --text treat all files as text |
280 |
| - --ignore-space-at-eol ignore changes in whitespace at EOL |
281 |
| - -b, --ignore-space-change ignore changes in amount of whitespace |
282 |
| - -w, --ignore-all-space ignore whitespace when comparing lines |
283 |
| - --ignored show ignored files as well |
284 |
| - --untracked show untracked files |
285 |
| - --patience generate diff using the patience algorithm |
286 |
| - --minimal spend extra time to find smallest diff |
287 |
| - --stat generate a diffstat |
288 |
| - --numstat similar to --stat, but more machine friendly |
289 |
| - --shortstat only output last line of --stat |
290 |
| - --summary output condensed summary of header info |
291 |
| - -M, --find-renames <n> set threshold for findind renames (default 50) |
292 |
| - -C, --find-copies <n> set threshold for finding copies (default 50) |
293 |
| - --find-copies-harder inspect unmodified files for sources of copies |
294 |
| - -B, --break-rewrites break complete rewrite changes into pairs |
295 |
| - -U, --unified <n> lints of context to show |
296 |
| - --inter-hunk-context <n> maximum lines of change between hunks |
297 |
| - --abbrev <n> length to abbreviate commits to |
298 |
| - --src-prefix <s> show given source prefix instead of 'a/' |
299 |
| - --dst-prefix <s> show given destinction prefix instead of 'b/' |
300 |
| - --git-dir <path> path to git repository to use |
301 |
| - -h, --help show this message |
302 |
| -"; |
303 |
| - |
304 |
| - let args = Docopt::new(USAGE) |
305 |
| - .and_then(|d| d.deserialize()) |
306 |
| - .unwrap_or_else(|e| e.exit()); |
| 330 | + let args = Args::from_args(); |
307 | 331 | match run(&args) {
|
308 | 332 | Ok(()) => {}
|
309 | 333 | Err(e) => println!("error: {}", e),
|
|
0 commit comments