Skip to content

Commit 1f172e4

Browse files
committed
refactor: extract registry and index arg for reuse
1 parent d5336f8 commit 1f172e4

File tree

13 files changed

+25
-21
lines changed

13 files changed

+25
-21
lines changed

src/bin/cargo/commands/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn cli() -> Command {
77
.about("Create a new cargo package in an existing directory")
88
.arg(Arg::new("path").action(ArgAction::Set).default_value("."))
99
.arg_new_opts()
10-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
10+
.arg_registry("Registry to use")
1111
.arg_quiet()
1212
.after_help(color_print::cstr!(
1313
"Run `<cyan,bold>cargo help init</>` for more detailed information.\n"

src/bin/cargo/commands/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn cli() -> Command {
66
subcommand("login")
77
.about("Log in to a registry.")
88
.arg(Arg::new("token").action(ArgAction::Set))
9-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
9+
.arg_registry("Registry to use")
1010
.arg(
1111
Arg::new("args")
1212
.help("Arguments for the credential provider (unstable)")

src/bin/cargo/commands/logout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cargo::ops;
44
pub fn cli() -> Command {
55
subcommand("logout")
66
.about("Remove an API token from the registry locally")
7-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
7+
.arg_registry("Registry to use")
88
.arg_quiet()
99
.after_help(color_print::cstr!(
1010
"Run `<cyan,bold>cargo help logout</>` for more detailed information.\n"

src/bin/cargo/commands/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn cli() -> Command {
77
.about("Create a new cargo package at <path>")
88
.arg(Arg::new("path").action(ArgAction::Set).required(true))
99
.arg_new_opts()
10-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
10+
.arg_registry("Registry to use")
1111
.arg_quiet()
1212
.after_help(color_print::cstr!(
1313
"Run `<cyan,bold>cargo help new</>` for more detailed information.\n"

src/bin/cargo/commands/owner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub fn cli() -> Command {
2424
.short('r'),
2525
)
2626
.arg(flag("list", "List owners of a crate").short('l'))
27-
.arg(opt("index", "Registry index to modify owners for").value_name("INDEX"))
27+
.arg_index("Registry index URL to modify owners for")
28+
.arg_registry("Registry to modify owners for")
2829
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
29-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
3030
.arg_quiet()
3131
.after_help(color_print::cstr!(
3232
"Run `<cyan,bold>cargo help owner</>` for more detailed information.\n"

src/bin/cargo/commands/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ pub fn cli() -> Command {
66
subcommand("publish")
77
.about("Upload a package to the registry")
88
.arg_dry_run("Perform all checks without uploading")
9-
.arg_index()
10-
.arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
9+
.arg_index("Registry index URL to upload the package to")
10+
.arg_registry("Registry to upload the package to")
1111
.arg(opt("token", "Token to use when uploading").value_name("TOKEN"))
1212
.arg(flag(
1313
"no-verify",

src/bin/cargo/commands/search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub fn cli() -> Command {
1515
)
1616
.value_name("LIMIT"),
1717
)
18-
.arg_index()
19-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
18+
.arg_index("Registry index URL to search packages in")
19+
.arg_registry("Registry to search packages in")
2020
.arg_quiet()
2121
.after_help(color_print::cstr!(
2222
"Run `<cyan,bold>cargo help search</>` for more detailed information.\n"

src/bin/cargo/commands/yank.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn cli() -> Command {
1616
"undo",
1717
"Undo a yank, putting a version back into the index",
1818
))
19-
.arg(opt("index", "Registry index to yank from").value_name("INDEX"))
20-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
19+
.arg_index("Registry index URL to yank from")
20+
.arg_registry("Registry to yank from")
2121
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
2222
.arg_quiet()
2323
.after_help(color_print::cstr!(

src/cargo/util/command_prelude.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,12 @@ pub trait CommandExt: Sized {
286286
)
287287
}
288288

289-
fn arg_index(self) -> Self {
290-
self._arg(opt("index", "Registry index URL to upload the package to").value_name("INDEX"))
289+
fn arg_registry(self, help: &'static str) -> Self {
290+
self._arg(opt("registry", help).value_name("REGISTRY"))
291+
}
292+
293+
fn arg_index(self, help: &'static str) -> Self {
294+
self._arg(opt("index", help).value_name("INDEX"))
291295
}
292296

293297
fn arg_dry_run(self, dry_run: &'static str) -> Self {

tests/testsuite/cargo_owner/help/stdout.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Options:
99
-a, --add <LOGIN> Name of a user or team to invite as an owner
1010
-r, --remove <LOGIN> Name of a user or team to remove as an owner
1111
-l, --list List owners of a crate
12-
--index <INDEX> Registry index to modify owners for
12+
--index <INDEX> Registry index URL to modify owners for
13+
--registry <REGISTRY> Registry to modify owners for
1314
--token <TOKEN> API token to use when authenticating
14-
--registry <REGISTRY> Registry to use
1515
-q, --quiet Do not print cargo log messages
1616
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
1717
--color <WHEN> Coloring: auto, always, never

0 commit comments

Comments
 (0)