rust/rhg/src/commands/debugdata.rs
changeset 46552 184e46550dc8
parent 46543 a6e4e4650bac
child 46553 1ecaf09d9964
equal deleted inserted replaced
46551:eace48b4a786 46552:184e46550dc8
     1 use crate::commands::Command;
       
     2 use crate::error::CommandError;
     1 use crate::error::CommandError;
     3 use crate::ui::Ui;
     2 use crate::ui::Ui;
       
     3 use clap::ArgMatches;
     4 use hg::config::Config;
     4 use hg::config::Config;
     5 use hg::operations::{debug_data, DebugDataKind};
     5 use hg::operations::{debug_data, DebugDataKind};
     6 use hg::repo::Repo;
     6 use hg::repo::Repo;
     7 use micro_timer::timed;
     7 use micro_timer::timed;
     8 
     8 
     9 pub const HELP_TEXT: &str = "
     9 pub const HELP_TEXT: &str = "
    10 Dump the contents of a data file revision
    10 Dump the contents of a data file revision
    11 ";
    11 ";
    12 
    12 
    13 pub struct DebugDataCommand<'a> {
    13 #[timed]
    14     rev: &'a str,
    14 pub fn run(
    15     kind: DebugDataKind,
    15     ui: &Ui,
       
    16     config: &Config,
       
    17     args: &ArgMatches,
       
    18 ) -> Result<(), CommandError> {
       
    19     let rev = args
       
    20         .value_of("rev")
       
    21         .expect("rev should be a required argument");
       
    22     let kind =
       
    23         match (args.is_present("changelog"), args.is_present("manifest")) {
       
    24             (true, false) => DebugDataKind::Changelog,
       
    25             (false, true) => DebugDataKind::Manifest,
       
    26             (true, true) => {
       
    27                 unreachable!("Should not happen since options are exclusive")
       
    28             }
       
    29             (false, false) => {
       
    30                 unreachable!("Should not happen since options are required")
       
    31             }
       
    32         };
       
    33 
       
    34     let repo = Repo::find(config)?;
       
    35     let data = debug_data(&repo, rev, kind).map_err(|e| (e, rev))?;
       
    36 
       
    37     let mut stdout = ui.stdout_buffer();
       
    38     stdout.write_all(&data)?;
       
    39     stdout.flush()?;
       
    40 
       
    41     Ok(())
    16 }
    42 }
    17 
       
    18 impl<'a> DebugDataCommand<'a> {
       
    19     pub fn new(rev: &'a str, kind: DebugDataKind) -> Self {
       
    20         DebugDataCommand { rev, kind }
       
    21     }
       
    22 }
       
    23 
       
    24 impl<'a> Command for DebugDataCommand<'a> {
       
    25     #[timed]
       
    26     fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> {
       
    27         let repo = Repo::find(config)?;
       
    28         let data = debug_data(&repo, self.rev, self.kind)
       
    29             .map_err(|e| (e, self.rev))?;
       
    30 
       
    31         let mut stdout = ui.stdout_buffer();
       
    32         stdout.write_all(&data)?;
       
    33         stdout.flush()?;
       
    34 
       
    35         Ok(())
       
    36     }
       
    37 }