Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ pub fn cli() -> Command {
.arg_quiet()
.arg(flag("workspace", "Only update the workspace packages").short('w'))
.arg_package_spec_simple("Package to update")
.arg(flag(
"aggressive",
"Force updating all dependencies of SPEC as well when used with -p",
))
.arg(
flag(
"aggressive",
"Force updating all dependencies of SPEC as well when used with -p",
)
.requires("package"),
)
.arg_dry_run("Don't actually write the lockfile")
.arg(
opt(
"precise",
"Update a single dependency to exactly PRECISE when used with -p",
)
.value_name("PRECISE"),
.value_name("PRECISE")
.requires("package"),
)
.arg_manifest_path()
.after_help("Run `cargo help update` for more detailed information.\n")
Expand Down
19 changes: 0 additions & 19 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> {
}

pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> {
// Currently this is only a warning, but after a transition period this will become
// a hard error.
// See https://github.com/rust-lang/cargo/issues/10919#issuecomment-1214464756.
// We should declare the `precise` and `aggressive` arguments
// require the `package` argument in the clap.
if opts.aggressive && opts.to_update.is_empty() {
ws.config().shell().warn(
"aggressive is only supported with \"--package <SPEC>\", \
this will become a hard error in a future release.",
)?;
}

if opts.precise.is_some() && opts.to_update.is_empty() {
ws.config().shell().warn(
"precise is only supported with \"--package <SPEC>\", \
this will become a hard error in a future release.",
)?;
}

if opts.aggressive && opts.precise.is_some() {
anyhow::bail!("cannot specify both aggressive and precise simultaneously")
}
Expand Down
20 changes: 14 additions & 6 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,15 @@ fn update_precise_without_package() {
Package::new("serde", "0.3.0").publish();

p.cargo("update --precise 0.3.0")
.with_status(1)
.with_stderr(
"\
[WARNING] precise is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
[ERROR] The following required arguments were not provided:
--package [<SPEC>]

Usage: cargo[EXE] update --package [<SPEC>] --precise <PRECISE>

For more information try '--help'
",
)
.run();
Expand Down Expand Up @@ -525,11 +529,15 @@ fn update_aggressive_without_package() {
Package::new("serde", "0.2.1").publish();

p.cargo("update --aggressive")
.with_status(1)
.with_stderr(
"\
[WARNING] aggressive is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
[ERROR] The following required arguments were not provided:
--package [<SPEC>]

Usage: cargo[EXE] update --package [<SPEC>] --aggressive

For more information try '--help'
",
)
.run();
Expand Down