Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(update): Tweak CLI behavior #12428

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ 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_dry_run("Don't actually write the lockfile")
.arg(
flag(
"aggressive",
"Force updating all dependencies of SPEC as well when used with -p",
)
.conflicts_with("precise"),
)
.arg(
opt(
"precise",
Expand All @@ -23,6 +25,7 @@ pub fn cli() -> Command {
.requires("package"),
)
.arg_manifest_path()
.arg_dry_run("Don't actually write the lockfile")
.after_help("Run `cargo help update` for more detailed information.\n")
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_update/help/stdout.log
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Options:
-w, --workspace Only update the workspace packages
-p, --package [<SPEC>] Package to update
--aggressive Force updating all dependencies of SPEC as well when used with -p
--dry-run Don't actually write the lockfile
--precise <PRECISE> Update a single dependency to exactly PRECISE when used with -p
--manifest-path <PATH> Path to Cargo.toml
--dry-run Don't actually write the lockfile
-h, --help Print help
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
Expand Down
40 changes: 40 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,46 @@ fn update_aggressive() {
.run();
}

#[cargo_test]
fn update_aggressive_conflicts_with_precise() {
Package::new("log", "0.1.0").publish();
Package::new("serde", "0.2.1").dep("log", "0.1").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []

[dependencies]
serde = "0.2"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check").run();

Package::new("log", "0.1.1").publish();
Package::new("serde", "0.2.2").dep("log", "0.1").publish();

p.cargo("update -p serde:0.2.1 --precise 0.2.2 --aggressive")
.with_status(1)
.with_stderr(
"\
error: the argument '--precise <PRECISE>' cannot be used with '--aggressive'

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

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

// cargo update should respect its arguments even without a lockfile.
// See issue "Running cargo update without a Cargo.lock ignores arguments"
// at <https://github.com/rust-lang/cargo/issues/6872>.
Expand Down