author | Simon Sapin <simon.sapin@octobus.net> |
Mon, 08 Feb 2021 21:05:36 +0100 | |
changeset 46553 | 1ecaf09d9964 |
parent 46552 | 184e46550dc8 |
child 46555 | d8730ff51d5a |
permissions | -rw-r--r-- |
46502
3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
1 |
use crate::error::CommandError; |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2 |
use crate::ui::Ui; |
46553
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
3 |
use clap::Arg; |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
4 |
use clap::ArgGroup; |
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
5 |
use clap::ArgMatches; |
46543
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46504
diff
changeset
|
6 |
use hg::config::Config; |
46504
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46502
diff
changeset
|
7 |
use hg::operations::{debug_data, DebugDataKind}; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46136
diff
changeset
|
8 |
use hg::repo::Repo; |
45536
b1cea0dc9db0
rhg: Add debug timing
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45534
diff
changeset
|
9 |
use micro_timer::timed; |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
10 |
|
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
11 |
pub const HELP_TEXT: &str = " |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
12 |
Dump the contents of a data file revision |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
13 |
"; |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 |
|
46553
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
15 |
pub fn args() -> clap::App<'static, 'static> { |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
16 |
clap::SubCommand::with_name("debugdata") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
17 |
.arg( |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
18 |
Arg::with_name("changelog") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
19 |
.help("open changelog") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
20 |
.short("-c") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
21 |
.long("--changelog"), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
22 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
23 |
.arg( |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
24 |
Arg::with_name("manifest") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
25 |
.help("open manifest") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
26 |
.short("-m") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
27 |
.long("--manifest"), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
28 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
29 |
.group( |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
30 |
ArgGroup::with_name("") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
31 |
.args(&["changelog", "manifest"]) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
32 |
.required(true), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
33 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
34 |
.arg( |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
35 |
Arg::with_name("rev") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
36 |
.help("revision") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
37 |
.required(true) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
38 |
.value_name("REV"), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
39 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
40 |
.about(HELP_TEXT) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
41 |
} |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
42 |
|
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
43 |
#[timed] |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
44 |
pub fn run( |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
45 |
ui: &Ui, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
46 |
config: &Config, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
47 |
args: &ArgMatches, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
48 |
) -> Result<(), CommandError> { |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
49 |
let rev = args |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
50 |
.value_of("rev") |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
51 |
.expect("rev should be a required argument"); |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
52 |
let kind = |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
53 |
match (args.is_present("changelog"), args.is_present("manifest")) { |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
54 |
(true, false) => DebugDataKind::Changelog, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
55 |
(false, true) => DebugDataKind::Manifest, |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
56 |
(true, true) => { |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
57 |
unreachable!("Should not happen since options are exclusive") |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
58 |
} |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
59 |
(false, false) => { |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
60 |
unreachable!("Should not happen since options are required") |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
61 |
} |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
62 |
}; |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
63 |
|
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
64 |
let repo = Repo::find(config)?; |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
65 |
let data = debug_data(&repo, rev, kind).map_err(|e| (e, rev))?; |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
66 |
|
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
67 |
let mut stdout = ui.stdout_buffer(); |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
68 |
stdout.write_all(&data)?; |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
69 |
stdout.flush()?; |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
70 |
|
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
71 |
Ok(()) |
45534
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
72 |
} |