Skip to content

Commit

Permalink
refactor: Resolve Arg::multiple deprecation
Browse files Browse the repository at this point in the history
Note: `cargo vendor --sync` did not use `multi_opt` and so it has both
multiple occurrences **and** multiple values.  If we want to deprecate
this, we'll need `unstable-grouped` to be stablized (or pin our clap
version) and ensure each group has only 1 value.
  • Loading branch information
epage committed Jan 6, 2022
1 parent 6e08a30 commit 92fa72d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/bin/cargo/cli.rs
Expand Up @@ -479,8 +479,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
.short('Z')
.value_name("FLAG")
.multiple(true)
.number_of_values(1)
.multiple_occurrences(true)
.global(true),
)
.subcommands(commands::builtin())
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/bench.rs
Expand Up @@ -13,7 +13,7 @@ pub fn cli() -> App {
.arg(
Arg::new("args")
.help("Arguments for the bench binary")
.multiple(true)
.multiple_values(true)
.last(true),
)
.arg_targets_all(
Expand Down
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/install.rs
Expand Up @@ -8,7 +8,11 @@ pub fn cli() -> App {
subcommand("install")
.about("Install a Rust binary. Default location is $HOME/.cargo/bin")
.arg_quiet()
.arg(Arg::new("crate").forbid_empty_values(true).multiple(true))
.arg(
Arg::new("crate")
.forbid_empty_values(true)
.multiple_values(true),
)
.arg(
opt("version", "Specify a version to install")
.alias("vers")
Expand Down
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/run.rs
Expand Up @@ -11,7 +11,11 @@ pub fn cli() -> App {
.setting(AppSettings::TrailingVarArg)
.about("Run a binary or example of the local package")
.arg_quiet()
.arg(Arg::new("args").allow_invalid_utf8(true).multiple(true))
.arg(
Arg::new("args")
.allow_invalid_utf8(true)
.multiple_values(true),
)
.arg_targets_bin_example(
"Name of the bin target to run",
"Name of the example target to run",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/rustc.rs
Expand Up @@ -10,7 +10,7 @@ pub fn cli() -> App {
.setting(AppSettings::TrailingVarArg)
.about("Compile a package, and pass extra options to the compiler")
.arg_quiet()
.arg(Arg::new("args").multiple(true).help("Rustc flags"))
.arg(Arg::new("args").multiple_values(true).help("Rustc flags"))
.arg_package("Package to build")
.arg_jobs()
.arg_targets_all(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/rustdoc.rs
Expand Up @@ -7,7 +7,7 @@ pub fn cli() -> App {
.setting(AppSettings::TrailingVarArg)
.about("Build a package's documentation, using specified custom flags.")
.arg_quiet()
.arg(Arg::new("args").multiple(true))
.arg(Arg::new("args").multiple_values(true))
.arg(opt(
"open",
"Opens the docs in a browser after the operation",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/search.rs
Expand Up @@ -8,7 +8,7 @@ pub fn cli() -> App {
subcommand("search")
.about("Search packages in crates.io")
.arg_quiet()
.arg(Arg::new("query").multiple(true))
.arg(Arg::new("query").multiple_values(true))
.arg_index()
.arg(
opt(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/test.rs
Expand Up @@ -15,7 +15,7 @@ pub fn cli() -> App {
.arg(
Arg::new("args")
.help("Arguments for the test binary")
.multiple(true)
.multiple_values(true)
.last(true),
)
.arg(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/uninstall.rs
Expand Up @@ -6,7 +6,7 @@ pub fn cli() -> App {
subcommand("uninstall")
.about("Remove a Rust binary")
.arg_quiet()
.arg(Arg::new("spec").multiple(true))
.arg(Arg::new("spec").multiple_values(true))
.arg_package_spec_simple("Package to uninstall")
.arg(multi_opt("bin", "NAME", "Only uninstall the binary NAME"))
.arg(opt("root", "Directory to uninstall packages from").value_name("DIR"))
Expand Down
3 changes: 2 additions & 1 deletion src/bin/cargo/commands/vendor.rs
Expand Up @@ -24,7 +24,8 @@ pub fn cli() -> App {
.help("Additional `Cargo.toml` to sync and vendor")
.value_name("TOML")
.allow_invalid_utf8(true)
.multiple(true),
.multiple_occurrences(true)
.multiple_values(true),
)
.arg(
Arg::new("respect-source-config")
Expand Down
12 changes: 3 additions & 9 deletions src/cargo/util/command_prelude.rs
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use crate::core::compiler::{BuildConfig, MessageFormat};
use crate::core::resolver::CliFeatures;
use crate::core::{Edition, Workspace};
Expand Down Expand Up @@ -264,20 +262,16 @@ pub fn optional_multi_opt(
) -> Arg<'static> {
opt(name, help)
.value_name(value_name)
.multiple(true)
.multiple_occurrences(true)
.multiple_values(true)
.min_values(0)
.number_of_values(1)
}

pub fn multi_opt(name: &'static str, value_name: &'static str, help: &'static str) -> Arg<'static> {
// Note that all `.multiple(true)` arguments in Cargo should specify
// `.number_of_values(1)` as well, so that `--foo val1 val2` is
// *not* parsed as `foo` with values ["val1", "val2"].
// `number_of_values` should become the default in clap 3.
opt(name, help)
.value_name(value_name)
.multiple(true)
.number_of_values(1)
.multiple_occurrences(true)
}

pub fn subcommand(name: &'static str) -> App {
Expand Down

0 comments on commit 92fa72d

Please sign in to comment.