changeset 46501:1ecaf09d9964

rhg: Move subcommand CLI arguments definitions to respective modules Differential Revision: https://phab.mercurial-scm.org/D9968
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Feb 2021 21:05:36 +0100
parents 184e46550dc8
children 95d37db31479
files rust/rhg/src/commands/cat.rs rust/rhg/src/commands/debugdata.rs rust/rhg/src/commands/debugrequirements.rs rust/rhg/src/commands/files.rs rust/rhg/src/commands/root.rs rust/rhg/src/main.rs
diffstat 6 files changed, 79 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/commands/cat.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/commands/cat.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -1,5 +1,6 @@
 use crate::error::CommandError;
 use crate::ui::Ui;
+use clap::Arg;
 use clap::ArgMatches;
 use hg::config::Config;
 use hg::operations::cat;
@@ -12,6 +13,27 @@
 Output the current or given revision of files
 ";
 
+pub fn args() -> clap::App<'static, 'static> {
+    clap::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(HELP_TEXT)
+}
+
 #[timed]
 pub fn run(
     ui: &Ui,
--- a/rust/rhg/src/commands/debugdata.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/commands/debugdata.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -1,5 +1,7 @@
 use crate::error::CommandError;
 use crate::ui::Ui;
+use clap::Arg;
+use clap::ArgGroup;
 use clap::ArgMatches;
 use hg::config::Config;
 use hg::operations::{debug_data, DebugDataKind};
@@ -10,6 +12,34 @@
 Dump the contents of a data file revision
 ";
 
+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)
+}
+
 #[timed]
 pub fn run(
     ui: &Ui,
--- a/rust/rhg/src/commands/debugrequirements.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/commands/debugrequirements.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -8,6 +8,10 @@
 Print the current repo requirements.
 ";
 
+pub fn args() -> clap::App<'static, 'static> {
+    clap::SubCommand::with_name("debugrequirements").about(HELP_TEXT)
+}
+
 pub fn run(
     ui: &Ui,
     config: &Config,
--- a/rust/rhg/src/commands/files.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/commands/files.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -1,5 +1,6 @@
 use crate::error::CommandError;
 use crate::ui::Ui;
+use clap::Arg;
 use clap::ArgMatches;
 use hg::config::Config;
 use hg::operations::list_rev_tracked_files;
@@ -14,6 +15,19 @@
 Returns 0 on success.
 ";
 
+pub fn args() -> clap::App<'static, 'static> {
+    clap::SubCommand::with_name("files")
+        .arg(
+            Arg::with_name("rev")
+                .help("search the repository as it is in REV")
+                .short("-r")
+                .long("--revision")
+                .value_name("REV")
+                .takes_value(true),
+        )
+        .about(HELP_TEXT)
+}
+
 pub fn run(
     ui: &Ui,
     config: &Config,
--- a/rust/rhg/src/commands/root.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/commands/root.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -12,6 +12,10 @@
 Returns 0 on success.
 ";
 
+pub fn args() -> clap::App<'static, 'static> {
+    clap::SubCommand::with_name("root").about(HELP_TEXT)
+}
+
 pub fn run(
     ui: &Ui,
     config: &Config,
--- a/rust/rhg/src/main.rs	Mon Feb 08 20:33:04 2021 +0100
+++ b/rust/rhg/src/main.rs	Mon Feb 08 21:05:36 2021 +0100
@@ -1,10 +1,7 @@
 extern crate log;
 use clap::App;
 use clap::AppSettings;
-use clap::Arg;
-use clap::ArgGroup;
 use clap::ArgMatches;
-use clap::SubCommand;
 use format_bytes::format_bytes;
 
 mod commands;
@@ -20,72 +17,11 @@
         .setting(AppSettings::SubcommandRequired)
         .setting(AppSettings::VersionlessSubcommands)
         .version("0.0.1")
-        .subcommand(
-            SubCommand::with_name("root").about(commands::root::HELP_TEXT),
-        )
-        .subcommand(
-            SubCommand::with_name("files")
-                .arg(
-                    Arg::with_name("rev")
-                        .help("search the repository as it is in REV")
-                        .short("-r")
-                        .long("--revision")
-                        .value_name("REV")
-                        .takes_value(true),
-                )
-                .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(
-                    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"),
-                ),
-        )
-        .subcommand(
-            SubCommand::with_name("debugrequirements")
-                .about(commands::debugrequirements::HELP_TEXT),
-        );
+        .subcommand(commands::root::args())
+        .subcommand(commands::files::args())
+        .subcommand(commands::cat::args())
+        .subcommand(commands::debugdata::args())
+        .subcommand(commands::debugrequirements::args());
 
     let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
         let _ = ui::Ui::new().writeln_stderr_str(&err.message);