rust/rhg/src/main.rs
changeset 45542 33ded2d3f4fc
parent 45537 2f8227a12592
child 45923 ead435aa5294
--- 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>
 {