##// END OF EJS Templates
rhg: replace command structs with functions...
rhg: replace command structs with functions The `Command` trait was not used in any generic context, and the struct where nothing more than holders for values parsed from CLI arguments to be available to a `run` method. Differential Revision: https://phab.mercurial-scm.org/D9967

File last commit:

r47231:1a00a578 default
r47250:184e4655 default
Show More
debugdata.rs
42 lines | 1.1 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field...
r47163 use crate::error::CommandError;
Antoine Cezar
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099 use crate::ui::Ui;
Simon Sapin
rhg: replace command structs with functions...
r47250 use clap::ArgMatches;
Simon Sapin
rhg: Parse system and user configuration at program start...
r47213 use hg::config::Config;
Simon Sapin
rhg: replace `map_*_error` functions with `From` impls...
r47165 use hg::operations::{debug_data, DebugDataKind};
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use hg::repo::Repo;
Antoine Cezar
rhg: Add debug timing...
r46101 use micro_timer::timed;
Antoine Cezar
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099
pub const HELP_TEXT: &str = "
Dump the contents of a data file revision
";
Simon Sapin
rhg: replace command structs with functions...
r47250 #[timed]
pub fn run(
ui: &Ui,
config: &Config,
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
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099
Simon Sapin
rhg: replace command structs with functions...
r47250 let repo = Repo::find(config)?;
let data = debug_data(&repo, rev, kind).map_err(|e| (e, rev))?;
Antoine Cezar
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099
Simon Sapin
rhg: replace command structs with functions...
r47250 let mut stdout = ui.stdout_buffer();
stdout.write_all(&data)?;
stdout.flush()?;
Antoine Cezar
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099
Simon Sapin
rhg: replace command structs with functions...
r47250 Ok(())
Antoine Cezar
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand...
r46099 }