From 1f172e4b76d7f900cc6d81235bfea3ba73fbe64c Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 15 Sep 2023 18:30:28 +0800 Subject: [PATCH] refactor: extract `registry` and `index` arg for reuse --- src/bin/cargo/commands/init.rs | 2 +- src/bin/cargo/commands/login.rs | 2 +- src/bin/cargo/commands/logout.rs | 2 +- src/bin/cargo/commands/new.rs | 2 +- src/bin/cargo/commands/owner.rs | 4 ++-- src/bin/cargo/commands/publish.rs | 4 ++-- src/bin/cargo/commands/search.rs | 4 ++-- src/bin/cargo/commands/yank.rs | 4 ++-- src/cargo/util/command_prelude.rs | 8 ++++++-- tests/testsuite/cargo_owner/help/stdout.log | 4 ++-- tests/testsuite/cargo_publish/help/stdout.log | 2 +- tests/testsuite/cargo_search/help/stdout.log | 4 ++-- tests/testsuite/cargo_yank/help/stdout.log | 4 ++-- 13 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/bin/cargo/commands/init.rs b/src/bin/cargo/commands/init.rs index d699c2c49..48409d827 100644 --- a/src/bin/cargo/commands/init.rs +++ b/src/bin/cargo/commands/init.rs @@ -7,7 +7,7 @@ pub fn cli() -> Command { .about("Create a new cargo package in an existing directory") .arg(Arg::new("path").action(ArgAction::Set).default_value(".")) .arg_new_opts() - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_registry("Registry to use") .arg_quiet() .after_help(color_print::cstr!( "Run `cargo help init` for more detailed information.\n" diff --git a/src/bin/cargo/commands/login.rs b/src/bin/cargo/commands/login.rs index 262e3d6b0..89ebe855f 100644 --- a/src/bin/cargo/commands/login.rs +++ b/src/bin/cargo/commands/login.rs @@ -6,7 +6,7 @@ pub fn cli() -> Command { subcommand("login") .about("Log in to a registry.") .arg(Arg::new("token").action(ArgAction::Set)) - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_registry("Registry to use") .arg( Arg::new("args") .help("Arguments for the credential provider (unstable)") diff --git a/src/bin/cargo/commands/logout.rs b/src/bin/cargo/commands/logout.rs index a4fae5bd6..40f8d83c7 100644 --- a/src/bin/cargo/commands/logout.rs +++ b/src/bin/cargo/commands/logout.rs @@ -4,7 +4,7 @@ use cargo::ops; pub fn cli() -> Command { subcommand("logout") .about("Remove an API token from the registry locally") - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_registry("Registry to use") .arg_quiet() .after_help(color_print::cstr!( "Run `cargo help logout` for more detailed information.\n" diff --git a/src/bin/cargo/commands/new.rs b/src/bin/cargo/commands/new.rs index a5dff2721..c8d19218f 100644 --- a/src/bin/cargo/commands/new.rs +++ b/src/bin/cargo/commands/new.rs @@ -7,7 +7,7 @@ pub fn cli() -> Command { .about("Create a new cargo package at ") .arg(Arg::new("path").action(ArgAction::Set).required(true)) .arg_new_opts() - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_registry("Registry to use") .arg_quiet() .after_help(color_print::cstr!( "Run `cargo help new` for more detailed information.\n" diff --git a/src/bin/cargo/commands/owner.rs b/src/bin/cargo/commands/owner.rs index c9deaef51..2c3ab0da0 100644 --- a/src/bin/cargo/commands/owner.rs +++ b/src/bin/cargo/commands/owner.rs @@ -24,9 +24,9 @@ pub fn cli() -> Command { .short('r'), ) .arg(flag("list", "List owners of a crate").short('l')) - .arg(opt("index", "Registry index to modify owners for").value_name("INDEX")) + .arg_index("Registry index URL to modify owners for") + .arg_registry("Registry to modify owners for") .arg(opt("token", "API token to use when authenticating").value_name("TOKEN")) - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg_quiet() .after_help(color_print::cstr!( "Run `cargo help owner` for more detailed information.\n" diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index 34108d45d..f8377b823 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -6,8 +6,8 @@ pub fn cli() -> Command { subcommand("publish") .about("Upload a package to the registry") .arg_dry_run("Perform all checks without uploading") - .arg_index() - .arg(opt("registry", "Registry to publish to").value_name("REGISTRY")) + .arg_index("Registry index URL to upload the package to") + .arg_registry("Registry to upload the package to") .arg(opt("token", "Token to use when uploading").value_name("TOKEN")) .arg(flag( "no-verify", diff --git a/src/bin/cargo/commands/search.rs b/src/bin/cargo/commands/search.rs index 90aadcb27..199c2bdba 100644 --- a/src/bin/cargo/commands/search.rs +++ b/src/bin/cargo/commands/search.rs @@ -15,8 +15,8 @@ pub fn cli() -> Command { ) .value_name("LIMIT"), ) - .arg_index() - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_index("Registry index URL to search packages in") + .arg_registry("Registry to search packages in") .arg_quiet() .after_help(color_print::cstr!( "Run `cargo help search` for more detailed information.\n" diff --git a/src/bin/cargo/commands/yank.rs b/src/bin/cargo/commands/yank.rs index 665683915..9097cb31f 100644 --- a/src/bin/cargo/commands/yank.rs +++ b/src/bin/cargo/commands/yank.rs @@ -16,8 +16,8 @@ pub fn cli() -> Command { "undo", "Undo a yank, putting a version back into the index", )) - .arg(opt("index", "Registry index to yank from").value_name("INDEX")) - .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .arg_index("Registry index URL to yank from") + .arg_registry("Registry to yank from") .arg(opt("token", "API token to use when authenticating").value_name("TOKEN")) .arg_quiet() .after_help(color_print::cstr!( diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index f55e44f2c..f05192f02 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -286,8 +286,12 @@ pub trait CommandExt: Sized { ) } - fn arg_index(self) -> Self { - self._arg(opt("index", "Registry index URL to upload the package to").value_name("INDEX")) + fn arg_registry(self, help: &'static str) -> Self { + self._arg(opt("registry", help).value_name("REGISTRY")) + } + + fn arg_index(self, help: &'static str) -> Self { + self._arg(opt("index", help).value_name("INDEX")) } fn arg_dry_run(self, dry_run: &'static str) -> Self { diff --git a/tests/testsuite/cargo_owner/help/stdout.log b/tests/testsuite/cargo_owner/help/stdout.log index 3c8495ff0..580be3c88 100644 --- a/tests/testsuite/cargo_owner/help/stdout.log +++ b/tests/testsuite/cargo_owner/help/stdout.log @@ -9,9 +9,9 @@ Options: -a, --add Name of a user or team to invite as an owner -r, --remove Name of a user or team to remove as an owner -l, --list List owners of a crate - --index Registry index to modify owners for + --index Registry index URL to modify owners for + --registry Registry to modify owners for --token API token to use when authenticating - --registry Registry to use -q, --quiet Do not print cargo log messages -v, --verbose... Use verbose output (-vv very verbose/build.rs output) --color Coloring: auto, always, never diff --git a/tests/testsuite/cargo_publish/help/stdout.log b/tests/testsuite/cargo_publish/help/stdout.log index 313b937f9..db19a168d 100644 --- a/tests/testsuite/cargo_publish/help/stdout.log +++ b/tests/testsuite/cargo_publish/help/stdout.log @@ -5,7 +5,7 @@ Usage: cargo[EXE] publish [OPTIONS] Options: --dry-run Perform all checks without uploading --index Registry index URL to upload the package to - --registry Registry to publish to + --registry Registry to upload the package to --token Token to use when uploading --no-verify Don't verify the contents by building them --allow-dirty Allow dirty working directories to be packaged diff --git a/tests/testsuite/cargo_search/help/stdout.log b/tests/testsuite/cargo_search/help/stdout.log index 8572064e3..07170ad70 100644 --- a/tests/testsuite/cargo_search/help/stdout.log +++ b/tests/testsuite/cargo_search/help/stdout.log @@ -7,8 +7,8 @@ Arguments: Options: --limit Limit the number of results (default: 10, max: 100) - --index Registry index URL to upload the package to - --registry Registry to use + --index Registry index URL to search packages in + --registry Registry to search packages in -q, --quiet Do not print cargo log messages -v, --verbose... Use verbose output (-vv very verbose/build.rs output) --color Coloring: auto, always, never diff --git a/tests/testsuite/cargo_yank/help/stdout.log b/tests/testsuite/cargo_yank/help/stdout.log index 25b04e6c7..c6dbfeb9d 100644 --- a/tests/testsuite/cargo_yank/help/stdout.log +++ b/tests/testsuite/cargo_yank/help/stdout.log @@ -8,8 +8,8 @@ Arguments: Options: --version The version to yank or un-yank --undo Undo a yank, putting a version back into the index - --index Registry index to yank from - --registry Registry to use + --index Registry index URL to yank from + --registry Registry to yank from --token API token to use when authenticating -q, --quiet Do not print cargo log messages -v, --verbose... Use verbose output (-vv very verbose/build.rs output)