refactor(cli): Upgrade to clap v4

This commit is contained in:
Ed Page 2022-09-20 13:19:46 -05:00
parent a3e352e4b8
commit 96948f7a24
35 changed files with 105 additions and 114 deletions

View File

@ -62,7 +62,7 @@ toml_edit = { version = "0.14.3", features = ["serde", "easy", "perf"] }
unicode-xid = "0.2.0" unicode-xid = "0.2.0"
url = "2.2.2" url = "2.2.2"
walkdir = "2.2" walkdir = "2.2"
clap = "3.2.18" clap = "4.0.4"
unicode-width = "0.1.5" unicode-width = "0.1.5"
openssl = { version = '0.10.11', optional = true } openssl = { version = '0.10.11', optional = true }
im-rc = "15.0.0" im-rc = "15.0.0"

View File

@ -2,7 +2,7 @@ use anyhow::anyhow;
use cargo::core::shell::Shell; use cargo::core::shell::Shell;
use cargo::core::{features, CliUnstable}; use cargo::core::{features, CliUnstable};
use cargo::{self, drop_print, drop_println, CliResult, Config}; use cargo::{self, drop_print, drop_println, CliResult, Config};
use clap::{AppSettings, Arg, ArgMatches}; use clap::{Arg, ArgMatches};
use itertools::Itertools; use itertools::Itertools;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
@ -69,7 +69,7 @@ Available unstable (nightly-only) flags:
{} {}
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'", Run with 'cargo -Z [FLAG] [COMMAND]'",
joined joined
); );
if !config.nightly_features_allowed { if !config.nightly_features_allowed {
@ -406,14 +406,12 @@ impl GlobalArgs {
pub fn cli() -> Command { pub fn cli() -> Command {
let is_rustup = std::env::var_os("RUSTUP_HOME").is_some(); let is_rustup = std::env::var_os("RUSTUP_HOME").is_some();
let usage = if is_rustup { let usage = if is_rustup {
"cargo [+toolchain] [OPTIONS] [SUBCOMMAND]" "cargo [+toolchain] [OPTIONS] [COMMAND]"
} else { } else {
"cargo [OPTIONS] [SUBCOMMAND]" "cargo [OPTIONS] [COMMAND]"
}; };
Command::new("cargo") Command::new("cargo")
.allow_external_subcommands(true) .allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.setting(AppSettings::DeriveDisplayOrder)
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for // Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
// opening clap up to allow us to style our help template // opening clap up to allow us to style our help template
.disable_colored_help(true) .disable_colored_help(true)
@ -424,10 +422,9 @@ pub fn cli() -> Command {
"\ "\
Rust's package manager Rust's package manager
USAGE: Usage: {usage}
{usage}
OPTIONS: Options:
{options} {options}
Some common cargo commands are (see all commands with --list): Some common cargo commands are (see all commands with --list):

View File

@ -14,21 +14,19 @@ use cargo::CargoResult;
pub fn cli() -> Command { pub fn cli() -> Command {
clap::Command::new("add") clap::Command::new("add")
.setting(clap::AppSettings::DeriveDisplayOrder)
.about("Add dependencies to a Cargo.toml manifest file") .about("Add dependencies to a Cargo.toml manifest file")
.override_usage( .override_usage(
"\ "\
cargo add [OPTIONS] <DEP>[@<VERSION>] ... cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] --path <PATH> ... cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --git <URL> ..." cargo add [OPTIONS] --git <URL> ..."
) )
.after_help("Run `cargo help add` for more detailed information.\n") .after_help("Run `cargo help add` for more detailed information.\n")
.group(clap::ArgGroup::new("selected").multiple(true).required(true)) .group(clap::ArgGroup::new("selected").multiple(true).required(true))
.args([ .args([
clap::Arg::new("crates") clap::Arg::new("crates")
.takes_value(true)
.value_name("DEP_ID") .value_name("DEP_ID")
.multiple_values(true) .num_args(0..)
.help("Reference to a package to add as a dependency") .help("Reference to a package to add as a dependency")
.long_help( .long_help(
"Reference to a package to add as a dependency "Reference to a package to add as a dependency
@ -46,7 +44,6 @@ You can reference a package by:
clap::Arg::new("features") clap::Arg::new("features")
.short('F') .short('F')
.long("features") .long("features")
.takes_value(true)
.value_name("FEATURES") .value_name("FEATURES")
.action(ArgAction::Append) .action(ArgAction::Append)
.help("Space or comma separated list of features to activate"), .help("Space or comma separated list of features to activate"),
@ -65,7 +62,7 @@ The package will be removed from your features.")
.overrides_with("optional"), .overrides_with("optional"),
clap::Arg::new("rename") clap::Arg::new("rename")
.long("rename") .long("rename")
.takes_value(true) .action(ArgAction::Set)
.value_name("NAME") .value_name("NAME")
.help("Rename the dependency") .help("Rename the dependency")
.long_help("Rename the dependency .long_help("Rename the dependency
@ -79,7 +76,7 @@ Example uses:
clap::Arg::new("package") clap::Arg::new("package")
.short('p') .short('p')
.long("package") .long("package")
.takes_value(true) .action(ArgAction::Set)
.value_name("SPEC") .value_name("SPEC")
.help("Package to modify"), .help("Package to modify"),
]) ])
@ -89,14 +86,14 @@ Example uses:
.args([ .args([
clap::Arg::new("path") clap::Arg::new("path")
.long("path") .long("path")
.takes_value(true) .action(ArgAction::Set)
.value_name("PATH") .value_name("PATH")
.help("Filesystem path to local crate to add") .help("Filesystem path to local crate to add")
.group("selected") .group("selected")
.conflicts_with("git"), .conflicts_with("git"),
clap::Arg::new("git") clap::Arg::new("git")
.long("git") .long("git")
.takes_value(true) .action(ArgAction::Set)
.value_name("URI") .value_name("URI")
.help("Git repository location") .help("Git repository location")
.long_help("Git repository location .long_help("Git repository location
@ -105,21 +102,21 @@ Without any other information, cargo will use latest commit on the main branch."
.group("selected"), .group("selected"),
clap::Arg::new("branch") clap::Arg::new("branch")
.long("branch") .long("branch")
.takes_value(true) .action(ArgAction::Set)
.value_name("BRANCH") .value_name("BRANCH")
.help("Git branch to download the crate from") .help("Git branch to download the crate from")
.requires("git") .requires("git")
.group("git-ref"), .group("git-ref"),
clap::Arg::new("tag") clap::Arg::new("tag")
.long("tag") .long("tag")
.takes_value(true) .action(ArgAction::Set)
.value_name("TAG") .value_name("TAG")
.help("Git tag to download the crate from") .help("Git tag to download the crate from")
.requires("git") .requires("git")
.group("git-ref"), .group("git-ref"),
clap::Arg::new("rev") clap::Arg::new("rev")
.long("rev") .long("rev")
.takes_value(true) .action(ArgAction::Set)
.value_name("REV") .value_name("REV")
.help("Git reference to download the crate from") .help("Git reference to download the crate from")
.long_help("Git reference to download the crate from .long_help("Git reference to download the crate from
@ -129,7 +126,7 @@ This is the catch all, handling hashes to named references in remote repositorie
.group("git-ref"), .group("git-ref"),
clap::Arg::new("registry") clap::Arg::new("registry")
.long("registry") .long("registry")
.takes_value(true) .action(ArgAction::Set)
.value_name("NAME") .value_name("NAME")
.help("Package registry for this dependency"), .help("Package registry for this dependency"),
]) ])
@ -151,7 +148,7 @@ Build-dependencies are the only dependencies available for use by build scripts
.group("section"), .group("section"),
clap::Arg::new("target") clap::Arg::new("target")
.long("target") .long("target")
.takes_value(true) .action(ArgAction::Set)
.value_name("TARGET") .value_name("TARGET")
.value_parser(clap::builder::NonEmptyStringValueParser::new()) .value_parser(clap::builder::NonEmptyStringValueParser::new())
.help("Add as dependency to the given target platform") .help("Add as dependency to the given target platform")

View File

@ -8,13 +8,13 @@ pub fn cli() -> Command {
.arg_quiet() .arg_quiet()
.arg( .arg(
Arg::new("BENCHNAME") Arg::new("BENCHNAME")
.action(ArgAction::Set)
.help("If specified, only run benches containing this string in their names"), .help("If specified, only run benches containing this string in their names"),
) )
.arg( .arg(
Arg::new("args") Arg::new("args")
.help("Arguments for the bench binary") .help("Arguments for the bench binary")
.multiple_values(true) .num_args(0..),
.last(true),
) )
.arg_targets_all( .arg_targets_all(
"Benchmark only this package's library", "Benchmark only this package's library",

View File

@ -9,7 +9,11 @@ pub fn cli() -> Command {
.arg_required_else_help(true) .arg_required_else_help(true)
.subcommand( .subcommand(
subcommand("get") subcommand("get")
.arg(Arg::new("key").help("The config key to display")) .arg(
Arg::new("key")
.action(ArgAction::Set)
.help("The config key to display"),
)
.arg( .arg(
opt("format", "Display format") opt("format", "Display format")
.value_parser(cargo_config::ConfigFormat::POSSIBLE_VALUES) .value_parser(cargo_config::ConfigFormat::POSSIBLE_VALUES)

View File

@ -1,10 +1,10 @@
use crate::command_prelude::*; use crate::command_prelude::*;
const REMOVED: &str = "The `git-checkout` subcommand has been removed."; const REMOVED: &str = "The `git-checkout` command has been removed.";
pub fn cli() -> Command { pub fn cli() -> Command {
subcommand("git-checkout") subcommand("git-checkout")
.about("This subcommand has been removed") .about("This command has been removed")
.hide(true) .hide(true)
.override_help(REMOVED) .override_help(REMOVED)
} }

View File

@ -15,11 +15,11 @@ const COMPRESSED_MAN: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/man.tgz"
pub fn cli() -> Command { pub fn cli() -> Command {
subcommand("help") subcommand("help")
.about("Displays help for a cargo subcommand") .about("Displays help for a cargo subcommand")
.arg(Arg::new("SUBCOMMAND")) .arg(Arg::new("COMMAND").action(ArgAction::Set))
} }
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let subcommand = args.get_one::<String>("SUBCOMMAND"); let subcommand = args.get_one::<String>("COMMAND");
if let Some(subcommand) = subcommand { if let Some(subcommand) = subcommand {
if !try_help(config, subcommand)? { if !try_help(config, subcommand)? {
crate::execute_external_subcommand( crate::execute_external_subcommand(

View File

@ -6,7 +6,7 @@ pub fn cli() -> Command {
subcommand("init") subcommand("init")
.about("Create a new cargo package in an existing directory") .about("Create a new cargo package in an existing directory")
.arg_quiet() .arg_quiet()
.arg(Arg::new("path").default_value(".")) .arg(Arg::new("path").action(ArgAction::Set).default_value("."))
.arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg(opt("registry", "Registry to use").value_name("REGISTRY"))
.arg_new_opts() .arg_new_opts()
.after_help("Run `cargo help init` for more detailed information.\n") .after_help("Run `cargo help init` for more detailed information.\n")

View File

@ -13,7 +13,7 @@ pub fn cli() -> Command {
.arg( .arg(
Arg::new("crate") Arg::new("crate")
.value_parser(clap::builder::NonEmptyStringValueParser::new()) .value_parser(clap::builder::NonEmptyStringValueParser::new())
.multiple_values(true), .num_args(0..),
) )
.arg( .arg(
opt("version", "Specify a version to install") opt("version", "Specify a version to install")

View File

@ -9,7 +9,7 @@ pub fn cli() -> Command {
If token is not specified, it will be read from stdin.", If token is not specified, it will be read from stdin.",
) )
.arg_quiet() .arg_quiet()
.arg(Arg::new("token")) .arg(Arg::new("token").action(ArgAction::Set))
.arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg(opt("registry", "Registry to use").value_name("REGISTRY"))
.after_help("Run `cargo help login` for more detailed information.\n") .after_help("Run `cargo help login` for more detailed information.\n")
} }

View File

@ -6,7 +6,7 @@ pub fn cli() -> Command {
subcommand("new") subcommand("new")
.about("Create a new cargo package at <path>") .about("Create a new cargo package at <path>")
.arg_quiet() .arg_quiet()
.arg(Arg::new("path").required(true)) .arg(Arg::new("path").action(ArgAction::Set).required(true))
.arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg(opt("registry", "Registry to use").value_name("REGISTRY"))
.arg_new_opts() .arg_new_opts()
.after_help("Run `cargo help new` for more detailed information.\n") .after_help("Run `cargo help new` for more detailed information.\n")

View File

@ -6,7 +6,7 @@ pub fn cli() -> Command {
subcommand("owner") subcommand("owner")
.about("Manage the owners of a crate on the registry") .about("Manage the owners of a crate on the registry")
.arg_quiet() .arg_quiet()
.arg(Arg::new("crate")) .arg(Arg::new("crate").action(ArgAction::Set))
.arg( .arg(
multi_opt( multi_opt(
"add", "add",

View File

@ -7,7 +7,7 @@ pub fn cli() -> Command {
subcommand("pkgid") subcommand("pkgid")
.about("Print a fully qualified package specification") .about("Print a fully qualified package specification")
.arg_quiet() .arg_quiet()
.arg(Arg::new("spec")) .arg(Arg::new("spec").action(ArgAction::Set))
.arg_package("Argument to get the package ID specifier for") .arg_package("Argument to get the package ID specifier for")
.arg_manifest_path() .arg_manifest_path()
.after_help("Run `cargo help pkgid` for more detailed information.\n") .after_help("Run `cargo help pkgid` for more detailed information.\n")

View File

@ -14,7 +14,7 @@ pub fn cli() -> Command {
.arg( .arg(
Arg::new("args") Arg::new("args")
.value_parser(value_parser!(std::ffi::OsString)) .value_parser(value_parser!(std::ffi::OsString))
.multiple_values(true), .num_args(0..),
) )
.arg_targets_bin_example( .arg_targets_bin_example(
"Name of the bin target to run", "Name of the bin target to run",

View File

@ -10,7 +10,7 @@ pub fn cli() -> Command {
.trailing_var_arg(true) .trailing_var_arg(true)
.about("Compile a package, and pass extra options to the compiler") .about("Compile a package, and pass extra options to the compiler")
.arg_quiet() .arg_quiet()
.arg(Arg::new("args").multiple_values(true).help("Rustc flags")) .arg(Arg::new("args").num_args(0..).help("Rustc flags"))
.arg_package("Package to build") .arg_package("Package to build")
.arg_jobs() .arg_jobs()
.arg_targets_all( .arg_targets_all(

View File

@ -7,7 +7,7 @@ pub fn cli() -> Command {
.trailing_var_arg(true) .trailing_var_arg(true)
.about("Build a package's documentation, using specified custom flags.") .about("Build a package's documentation, using specified custom flags.")
.arg_quiet() .arg_quiet()
.arg(Arg::new("args").multiple_values(true)) .arg(Arg::new("args").num_args(0..))
.arg(flag( .arg(flag(
"open", "open",
"Opens the docs in a browser after the operation", "Opens the docs in a browser after the operation",

View File

@ -8,7 +8,7 @@ pub fn cli() -> Command {
subcommand("search") subcommand("search")
.about("Search packages in crates.io") .about("Search packages in crates.io")
.arg_quiet() .arg_quiet()
.arg(Arg::new("query").multiple_values(true)) .arg(Arg::new("query").num_args(0..))
.arg_index() .arg_index()
.arg( .arg(
opt( opt(

View File

@ -9,13 +9,13 @@ pub fn cli() -> Command {
.about("Execute all unit and integration tests and build examples of a local package") .about("Execute all unit and integration tests and build examples of a local package")
.arg( .arg(
Arg::new("TESTNAME") Arg::new("TESTNAME")
.action(ArgAction::Set)
.help("If specified, only run tests containing this string in their names"), .help("If specified, only run tests containing this string in their names"),
) )
.arg( .arg(
Arg::new("args") Arg::new("args")
.help("Arguments for the test binary") .help("Arguments for the test binary")
.multiple_values(true) .num_args(0..),
.last(true),
) )
.arg( .arg(
flag( flag(

View File

@ -6,7 +6,7 @@ pub fn cli() -> Command {
subcommand("uninstall") subcommand("uninstall")
.about("Remove a Rust binary") .about("Remove a Rust binary")
.arg_quiet() .arg_quiet()
.arg(Arg::new("spec").multiple_values(true)) .arg(Arg::new("spec").num_args(0..))
.arg_package_spec_simple("Package to uninstall") .arg_package_spec_simple("Package to uninstall")
.arg(multi_opt("bin", "NAME", "Only uninstall the binary NAME")) .arg(multi_opt("bin", "NAME", "Only uninstall the binary NAME"))
.arg(opt("root", "Directory to uninstall packages from").value_name("DIR")) .arg(opt("root", "Directory to uninstall packages from").value_name("DIR"))

View File

@ -9,6 +9,7 @@ pub fn cli() -> Command {
.arg_manifest_path() .arg_manifest_path()
.arg( .arg(
Arg::new("path") Arg::new("path")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(PathBuf)) .value_parser(clap::value_parser!(PathBuf))
.help("Where to vendor crates (`vendor` by default)"), .help("Where to vendor crates (`vendor` by default)"),
) )

View File

@ -6,7 +6,7 @@ pub fn cli() -> Command {
subcommand("yank") subcommand("yank")
.about("Remove a pushed crate from the index") .about("Remove a pushed crate from the index")
.arg_quiet() .arg_quiet()
.arg(Arg::new("crate")) .arg(Arg::new("crate").action(ArgAction::Set))
.arg( .arg(
opt("version", "The version to yank or un-yank") opt("version", "The version to yank or un-yank")
.alias("vers") .alias("vers")

View File

@ -168,7 +168,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
None => { None => {
let err = if cmd.starts_with('+') { let err = if cmd.starts_with('+') {
anyhow::format_err!( anyhow::format_err!(
"no such subcommand: `{}`\n\n\t\ "no such command: `{}`\n\n\t\
Cargo does not handle `+toolchain` directives.\n\t\ Cargo does not handle `+toolchain` directives.\n\t\
Did you mean to invoke `cargo` through `rustup` instead?", Did you mean to invoke `cargo` through `rustup` instead?",
cmd cmd
@ -178,7 +178,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c); let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c);
anyhow::format_err!( anyhow::format_err!(
"no such subcommand: `{}`{}\n\n\t\ "no such command: `{}`{}\n\n\t\
View all installed commands with `cargo --list`", View all installed commands with `cargo --list`",
cmd, cmd,
did_you_mean did_you_mean

View File

@ -20,12 +20,12 @@ use std::path::PathBuf;
pub use crate::core::compiler::CompileMode; pub use crate::core::compiler::CompileMode;
pub use crate::{CliError, CliResult, Config}; pub use crate::{CliError, CliResult, Config};
pub use clap::{value_parser, AppSettings, Arg, ArgAction, ArgMatches}; pub use clap::{value_parser, Arg, ArgAction, ArgMatches};
pub type Command = clap::Command<'static>; pub use clap::Command;
pub trait CommandExt: Sized { pub trait CommandExt: Sized {
fn _arg(self, arg: Arg<'static>) -> Self; fn _arg(self, arg: Arg) -> Self;
/// Do not use this method, it is only for backwards compatibility. /// Do not use this method, it is only for backwards compatibility.
/// Use `arg_package_spec_no_all` instead. /// Use `arg_package_spec_no_all` instead.
@ -256,40 +256,34 @@ pub trait CommandExt: Sized {
} }
impl CommandExt for Command { impl CommandExt for Command {
fn _arg(self, arg: Arg<'static>) -> Self { fn _arg(self, arg: Arg) -> Self {
self.arg(arg) self.arg(arg)
} }
} }
pub fn flag(name: &'static str, help: &'static str) -> Arg<'static> { pub fn flag(name: &'static str, help: &'static str) -> Arg {
Arg::new(name) Arg::new(name)
.long(name) .long(name)
.help(help) .help(help)
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
} }
pub fn opt(name: &'static str, help: &'static str) -> Arg<'static> { pub fn opt(name: &'static str, help: &'static str) -> Arg {
Arg::new(name).long(name).help(help) Arg::new(name).long(name).help(help).action(ArgAction::Set)
} }
pub fn optional_opt(name: &'static str, help: &'static str) -> Arg<'static> { pub fn optional_opt(name: &'static str, help: &'static str) -> Arg {
opt(name, help).min_values(0) opt(name, help).num_args(0..=1)
} }
pub fn optional_multi_opt( pub fn optional_multi_opt(name: &'static str, value_name: &'static str, help: &'static str) -> Arg {
name: &'static str,
value_name: &'static str,
help: &'static str,
) -> Arg<'static> {
opt(name, help) opt(name, help)
.value_name(value_name) .value_name(value_name)
.num_args(0..=1)
.action(ArgAction::Append) .action(ArgAction::Append)
.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> { pub fn multi_opt(name: &'static str, value_name: &'static str, help: &'static str) -> Arg {
opt(name, help) opt(name, help)
.value_name(value_name) .value_name(value_name)
.action(ArgAction::Append) .action(ArgAction::Append)
@ -297,8 +291,6 @@ pub fn multi_opt(name: &'static str, value_name: &'static str, help: &'static st
pub fn subcommand(name: &'static str) -> Command { pub fn subcommand(name: &'static str) -> Command {
Command::new(name) Command::new(name)
.dont_collapse_args_in_usage(true)
.setting(AppSettings::DeriveDisplayOrder)
} }
/// Determines whether or not to gate `--profile` as unstable when resolving it. /// Determines whether or not to gate `--profile` as unstable when resolving it.
@ -792,7 +784,7 @@ pub fn values_os(args: &ArgMatches, name: &str) -> Vec<OsString> {
} }
#[track_caller] #[track_caller]
fn ignore_unknown<T: Default>(r: Result<T, clap::parser::MatchesError>) -> T { pub fn ignore_unknown<T: Default>(r: Result<T, clap::parser::MatchesError>) -> T {
match r { match r {
Ok(t) => t, Ok(t) => t,
Err(clap::parser::MatchesError::UnknownArgument { .. }) => Default::default(), Err(clap::parser::MatchesError::UnknownArgument { .. }) => Default::default(),

View File

@ -1,8 +1,7 @@
error: The argument '--dev' cannot be used with '--build' error: The argument '--dev' cannot be used with '--build'
USAGE: Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] <DEP>[@<VERSION>] ... cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --path <PATH> ... cargo add [OPTIONS] --git <URL> ...
cargo add [OPTIONS] --git <URL> ...
For more information try --help For more information try '--help'

View File

@ -1,10 +1,9 @@
error: Found argument '--flag' which wasn't expected, or isn't valid in this context error: Found argument '--flag' which wasn't expected, or isn't valid in this context
If you tried to supply `--flag` as a value rather than a flag, use `-- --flag` If you tried to supply '--flag' as a value rather than a flag, use '-- --flag'
USAGE: Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] <DEP>[@<VERSION>] ... cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --path <PATH> ... cargo add [OPTIONS] --git <URL> ...
cargo add [OPTIONS] --git <URL> ...
For more information try --help For more information try '--help'

View File

@ -1,3 +1,3 @@
error: The argument '--target <TARGET>' requires a value but none was supplied error: The argument '--target <TARGET>' requires a value but none was supplied
For more information try --help For more information try '--help'

View File

@ -1,9 +1,8 @@
error: The following required arguments were not provided: error: The following required arguments were not provided:
<DEP_ID|--path <PATH>|--git <URI>> <DEP_ID|--path <PATH>|--git <URI>>
USAGE: Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
cargo add [OPTIONS] <DEP>[@<VERSION>] ... cargo add [OPTIONS] --path <PATH> ...
cargo add [OPTIONS] --path <PATH> ... cargo add [OPTIONS] --git <URL> ...
cargo add [OPTIONS] --git <URL> ...
For more information try --help For more information try '--help'

View File

@ -156,7 +156,7 @@ fn find_closest_capital_c_to_c() {
.with_status(101) .with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: no such subcommand: `C` error: no such command: `C`
<tab>Did you mean `c`? <tab>Did you mean `c`?
", ",
@ -170,7 +170,7 @@ fn find_closest_capital_b_to_b() {
.with_status(101) .with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: no such subcommand: `B` error: no such command: `B`
<tab>Did you mean `b`? <tab>Did you mean `b`?
", ",
@ -184,7 +184,7 @@ fn find_closest_biuld_to_build() {
.with_status(101) .with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: no such subcommand: `biuld` error: no such command: `biuld`
<tab>Did you mean `build`? <tab>Did you mean `build`?
", ",
@ -235,7 +235,7 @@ fn find_closest_alias() {
.with_status(101) .with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: no such subcommand: `myalais` error: no such command: `myalais`
<tab>Did you mean `myalias`? <tab>Did you mean `myalias`?
", ",
@ -247,7 +247,7 @@ error: no such subcommand: `myalais`
.with_status(101) .with_status(101)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: no such subcommand: `myalais` error: no such command: `myalais`
", ",
) )
.with_stderr_does_not_contain( .with_stderr_does_not_contain(
@ -266,7 +266,7 @@ fn find_closest_dont_correct_nonsense() {
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
[ERROR] no such subcommand: `there-is-no-way-that-there-is-a-command-close-to-this` [ERROR] no such command: `there-is-no-way-that-there-is-a-command-close-to-this`
<tab>View all installed commands with `cargo --list`", <tab>View all installed commands with `cargo --list`",
) )
@ -279,7 +279,7 @@ fn displays_subcommand_on_error() {
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
[ERROR] no such subcommand: `invalid-command` [ERROR] no such command: `invalid-command`
<tab>View all installed commands with `cargo --list`", <tab>View all installed commands with `cargo --list`",
) )
@ -473,7 +473,7 @@ fn subcommand_leading_plus_output_contains() {
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
error: no such subcommand: `+nightly` error: no such command: `+nightly`
<tab>Cargo does not handle `+toolchain` directives. <tab>Cargo does not handle `+toolchain` directives.
<tab>Did you mean to invoke `cargo` through `rustup` instead?", <tab>Did you mean to invoke `cargo` through `rustup` instead?",
@ -487,7 +487,7 @@ fn full_did_you_mean() {
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
error: no such subcommand: `bluid` error: no such command: `bluid`
<tab>Did you mean `build`? <tab>Did you mean `build`?

View File

@ -1,8 +1,7 @@
error: Found argument '--flag' which wasn't expected, or isn't valid in this context error: Found argument '--flag' which wasn't expected, or isn't valid in this context
If you tried to supply `--flag` as a value rather than a flag, use `-- --flag` If you tried to supply '--flag' as a value rather than a flag, use '-- --flag'
USAGE: Usage: cargo[EXE] init <path>
cargo[EXE] init <path>
For more information try --help For more information try '--help'

View File

@ -1448,8 +1448,7 @@ fn not_both_vers_and_version() {
.with_status(1) .with_status(1)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: The argument '--version <VERSION>' was provided more than once, \ error: The argument '--version <VERSION>' was provided more than once, but cannot be used multiple times
but cannot be used multiple times
", ",
) )
.run(); .run();
@ -1652,7 +1651,7 @@ fn install_empty_argument() {
.arg("") .arg("")
.with_status(1) .with_status(1)
.with_stderr_contains( .with_stderr_contains(
"[ERROR] The argument '<crate>...' requires a value but none was supplied", "[ERROR] The argument '[crate]...' requires a value but none was supplied",
) )
.run(); .run();
} }

View File

@ -1911,7 +1911,7 @@ fn cargo_metadata_bad_version() {
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: \"2\" isn't a valid value for '--format-version <VERSION>' error: \"2\" isn't a valid value for '--format-version <VERSION>'
<tab>[possible values: 1] [possible values: 1]
", ",
) )
.run(); .run();

View File

@ -107,7 +107,7 @@ fn no_argument() {
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: The following required arguments were not provided: error: The following required arguments were not provided:
<path> <path>
", ",
) )
.run(); .run();

View File

@ -1314,9 +1314,16 @@ fn run_multiple_packages() {
cargo().with_stdout("foo").run(); cargo().with_stdout("foo").run();
cargo().arg("-p").arg("d1").arg("-p").arg("d2") cargo()
.with_status(1) .arg("-p")
.with_stderr_contains("error: The argument '--package [<SPEC>...]' was provided more than once, but cannot be used multiple times").run(); .arg("d1")
.arg("-p")
.arg("d2")
.with_status(1)
.with_stderr_contains(
"error: The argument '--package [<SPEC>]' was provided more than once, but cannot be used multiple times",
)
.run();
cargo() cargo()
.arg("-p") .arg("-p")

View File

@ -551,8 +551,7 @@ fn fail_with_multiple_packages() {
.with_status(1) .with_status(1)
.with_stderr_contains( .with_stderr_contains(
"\ "\
error: The argument '--package [<SPEC>...]' was provided more than once, \ error: The argument '--package [<SPEC>]' was provided more than once, but cannot be used multiple times
but cannot be used multiple times
", ",
) )
.run(); .run();

View File

@ -405,10 +405,9 @@ fn test_sync_argument() {
.with_stderr("\ .with_stderr("\
error: Found argument 'test_vendor' which wasn't expected, or isn't valid in this context error: Found argument 'test_vendor' which wasn't expected, or isn't valid in this context
USAGE: Usage: cargo[EXE] vendor [OPTIONS] [path]
cargo[EXE] vendor [OPTIONS] [path]
For more information try --help", For more information try '--help'",
) )
.with_status(1) .with_status(1)
.run(); .run();