debugdata.rs
74 lines
| 2.0 KiB
| application/rls-services+xml
|
RustLexer
Simon Sapin
|
r47163 | use crate::error::CommandError; | ||
Antoine Cezar
|
r46099 | use crate::ui::Ui; | ||
Simon Sapin
|
r47251 | use clap::Arg; | ||
use clap::ArgGroup; | ||||
Simon Sapin
|
r47250 | use clap::ArgMatches; | ||
Simon Sapin
|
r47213 | use hg::config::Config; | ||
Simon Sapin
|
r47165 | use hg::operations::{debug_data, DebugDataKind}; | ||
Simon Sapin
|
r46782 | use hg::repo::Repo; | ||
Antoine Cezar
|
r46101 | use micro_timer::timed; | ||
Simon Sapin
|
r47253 | use std::path::Path; | ||
Antoine Cezar
|
r46099 | |||
pub const HELP_TEXT: &str = " | ||||
Dump the contents of a data file revision | ||||
"; | ||||
Simon Sapin
|
r47251 | pub fn args() -> clap::App<'static, 'static> { | ||
clap::SubCommand::with_name("debugdata") | ||||
.arg( | ||||
Arg::with_name("changelog") | ||||
.help("open changelog") | ||||
.short("-c") | ||||
.long("--changelog"), | ||||
) | ||||
.arg( | ||||
Arg::with_name("manifest") | ||||
.help("open manifest") | ||||
.short("-m") | ||||
.long("--manifest"), | ||||
) | ||||
.group( | ||||
ArgGroup::with_name("") | ||||
.args(&["changelog", "manifest"]) | ||||
.required(true), | ||||
) | ||||
.arg( | ||||
Arg::with_name("rev") | ||||
.help("revision") | ||||
.required(true) | ||||
.value_name("REV"), | ||||
) | ||||
.about(HELP_TEXT) | ||||
} | ||||
Simon Sapin
|
r47250 | #[timed] | ||
pub fn run( | ||||
ui: &Ui, | ||||
config: &Config, | ||||
Simon Sapin
|
r47253 | repo_path: Option<&Path>, | ||
Simon Sapin
|
r47250 | args: &ArgMatches, | ||
) -> Result<(), CommandError> { | ||||
let rev = args | ||||
.value_of("rev") | ||||
.expect("rev should be a required argument"); | ||||
let kind = | ||||
match (args.is_present("changelog"), args.is_present("manifest")) { | ||||
(true, false) => DebugDataKind::Changelog, | ||||
(false, true) => DebugDataKind::Manifest, | ||||
(true, true) => { | ||||
unreachable!("Should not happen since options are exclusive") | ||||
} | ||||
(false, false) => { | ||||
unreachable!("Should not happen since options are required") | ||||
} | ||||
}; | ||||
Antoine Cezar
|
r46099 | |||
Simon Sapin
|
r47253 | let repo = Repo::find(config, repo_path)?; | ||
Simon Sapin
|
r47250 | let data = debug_data(&repo, rev, kind).map_err(|e| (e, rev))?; | ||
Antoine Cezar
|
r46099 | |||
Simon Sapin
|
r47250 | let mut stdout = ui.stdout_buffer(); | ||
stdout.write_all(&data)?; | ||||
stdout.flush()?; | ||||
Antoine Cezar
|
r46099 | |||
Simon Sapin
|
r47250 | Ok(()) | ||
Antoine Cezar
|
r46099 | } | ||