# HG changeset patch # User Simon Sapin # Date 2021-02-08 20:05:36 # Node ID 1ecaf09d996412e2589ce8e3c69a8a3d7af01a4f # Parent 184e46550dc89b317820b5cf4b122c37df81bdd3 rhg: Move subcommand CLI arguments definitions to respective modules Differential Revision: https://phab.mercurial-scm.org/D9968 diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs --- a/rust/rhg/src/commands/cat.rs +++ b/rust/rhg/src/commands/cat.rs @@ -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 @@ pub const HELP_TEXT: &str = " 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, diff --git a/rust/rhg/src/commands/debugdata.rs b/rust/rhg/src/commands/debugdata.rs --- a/rust/rhg/src/commands/debugdata.rs +++ b/rust/rhg/src/commands/debugdata.rs @@ -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 @@ pub const HELP_TEXT: &str = " 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, diff --git a/rust/rhg/src/commands/debugrequirements.rs b/rust/rhg/src/commands/debugrequirements.rs --- a/rust/rhg/src/commands/debugrequirements.rs +++ b/rust/rhg/src/commands/debugrequirements.rs @@ -8,6 +8,10 @@ pub const HELP_TEXT: &str = " 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, diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs --- a/rust/rhg/src/commands/files.rs +++ b/rust/rhg/src/commands/files.rs @@ -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 @@ List tracked files. 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, diff --git a/rust/rhg/src/commands/root.rs b/rust/rhg/src/commands/root.rs --- a/rust/rhg/src/commands/root.rs +++ b/rust/rhg/src/commands/root.rs @@ -12,6 +12,10 @@ Print the root directory of the current 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, diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs +++ b/rust/rhg/src/main.rs @@ -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 @@ fn main() { .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);