refactor: extract registry and index arg for reuse

This commit is contained in:
Weihang Lo 2023-09-15 18:30:28 +08:00
parent d5336f813d
commit 1f172e4b76
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
13 changed files with 25 additions and 21 deletions

View File

@ -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 `<cyan,bold>cargo help init</>` for more detailed information.\n"

View File

@ -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)")

View File

@ -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 `<cyan,bold>cargo help logout</>` for more detailed information.\n"

View File

@ -7,7 +7,7 @@ pub fn cli() -> Command {
.about("Create a new cargo package at <path>")
.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 `<cyan,bold>cargo help new</>` for more detailed information.\n"

View File

@ -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 `<cyan,bold>cargo help owner</>` for more detailed information.\n"

View File

@ -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",

View File

@ -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 `<cyan,bold>cargo help search</>` for more detailed information.\n"

View File

@ -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!(

View File

@ -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 {

View File

@ -9,9 +9,9 @@ Options:
-a, --add <LOGIN> Name of a user or team to invite as an owner
-r, --remove <LOGIN> Name of a user or team to remove as an owner
-l, --list List owners of a crate
--index <INDEX> Registry index to modify owners for
--index <INDEX> Registry index URL to modify owners for
--registry <REGISTRY> Registry to modify owners for
--token <TOKEN> API token to use when authenticating
--registry <REGISTRY> Registry to use
-q, --quiet Do not print cargo log messages
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never

View File

@ -5,7 +5,7 @@ Usage: cargo[EXE] publish [OPTIONS]
Options:
--dry-run Perform all checks without uploading
--index <INDEX> Registry index URL to upload the package to
--registry <REGISTRY> Registry to publish to
--registry <REGISTRY> Registry to upload the package to
--token <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

View File

@ -7,8 +7,8 @@ Arguments:
Options:
--limit <LIMIT> Limit the number of results (default: 10, max: 100)
--index <INDEX> Registry index URL to upload the package to
--registry <REGISTRY> Registry to use
--index <INDEX> Registry index URL to search packages in
--registry <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 <WHEN> Coloring: auto, always, never

View File

@ -8,8 +8,8 @@ Arguments:
Options:
--version <VERSION> The version to yank or un-yank
--undo Undo a yank, putting a version back into the index
--index <INDEX> Registry index to yank from
--registry <REGISTRY> Registry to use
--index <INDEX> Registry index URL to yank from
--registry <REGISTRY> Registry to yank from
--token <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)