diff rust/rhg/src/main.rs @ 45548:33ded2d3f4fc

rhg: add a limited `rhg cat -r` subcommand It only supports revision specification (rev or full hash) and the list of files to cat. Differential Revision: https://phab.mercurial-scm.org/D9052
author Antoine Cezar <antoine.cezar@octobus.net>
date Tue, 15 Sep 2020 16:51:11 +0200
parents 2f8227a12592
children ead435aa5294
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Fri Sep 11 17:32:53 2020 +0200
+++ b/rust/rhg/src/main.rs	Tue Sep 15 16:51:11 2020 +0200
@@ -38,6 +38,26 @@
                 .about(commands::files::HELP_TEXT),
         )
         .subcommand(
+            SubCommand::with_name("cat")
+                .arg(
+                    Arg::with_name("rev")
+                        .help("search the repository as it is in REV")
+                        .short("-r")
+                        .long("--revision")
+                        .value_name("REV")
+                        .takes_value(true),
+                )
+                .arg(
+                    clap::Arg::with_name("files")
+                        .required(true)
+                        .multiple(true)
+                        .empty_values(false)
+                        .value_name("FILE")
+                        .help("Activity to start: activity@category"),
+                )
+                .about(commands::cat::HELP_TEXT),
+        )
+        .subcommand(
             SubCommand::with_name("debugdata")
                 .about(commands::debugdata::HELP_TEXT)
                 .arg(
@@ -98,6 +118,9 @@
         ("files", Some(matches)) => {
             commands::files::FilesCommand::try_from(matches)?.run(&ui)
         }
+        ("cat", Some(matches)) => {
+            commands::cat::CatCommand::try_from(matches)?.run(&ui)
+        }
         ("debugdata", Some(matches)) => {
             commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui)
         }
@@ -114,6 +137,19 @@
     }
 }
 
+impl<'a> TryFrom<&'a ArgMatches<'_>> for commands::cat::CatCommand<'a> {
+    type Error = CommandError;
+
+    fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> {
+        let rev = args.value_of("rev");
+        let files = match args.values_of("files") {
+            Some(files) => files.collect(),
+            None => vec![],
+        };
+        Ok(commands::cat::CatCommand::new(rev, files))
+    }
+}
+
 impl<'a> TryFrom<&'a ArgMatches<'_>>
     for commands::debugdata::DebugDataCommand<'a>
 {