Skip to content

Commit baebd2b

Browse files
committed
Auto merge of #12428 - epage:update, r=weihanglo
fix(update): Tweak CLI behavior ### What does this PR try to resolve? When looking at `cargo update` for #12425, I noticed that the two flags related to `--package` were not next to it or each other. I figured grouping them like that would make things easier to browse. When looking into that, I noticed that the two flags conflict and figured we'd provide a better error message if we did that through clap. ### How should we test and review this PR? Looking per commit will help show the behavior changes. ### Additional information I wanted to scope this to being simple, non-controversial, low effort, incremental improvements with this change so I did not look into the history of `--aggressive` not requiring `--package` like `--precise` does and figure out if there is any consistency we can be working towards.
2 parents 772fd5f + 4fd0c3c commit baebd2b

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

src/bin/cargo/commands/update.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ pub fn cli() -> Command {
99
.arg_quiet()
1010
.arg(flag("workspace", "Only update the workspace packages").short('w'))
1111
.arg_package_spec_simple("Package to update")
12-
.arg(flag(
13-
"aggressive",
14-
"Force updating all dependencies of SPEC as well when used with -p",
15-
))
16-
.arg_dry_run("Don't actually write the lockfile")
12+
.arg(
13+
flag(
14+
"aggressive",
15+
"Force updating all dependencies of SPEC as well when used with -p",
16+
)
17+
.conflicts_with("precise"),
18+
)
1719
.arg(
1820
opt(
1921
"precise",
@@ -23,6 +25,7 @@ pub fn cli() -> Command {
2325
.requires("package"),
2426
)
2527
.arg_manifest_path()
28+
.arg_dry_run("Don't actually write the lockfile")
2629
.after_help("Run `cargo help update` for more detailed information.\n")
2730
}
2831

tests/testsuite/cargo_update/help/stdout.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Options:
77
-w, --workspace Only update the workspace packages
88
-p, --package [<SPEC>] Package to update
99
--aggressive Force updating all dependencies of SPEC as well when used with -p
10-
--dry-run Don't actually write the lockfile
1110
--precise <PRECISE> Update a single dependency to exactly PRECISE when used with -p
1211
--manifest-path <PATH> Path to Cargo.toml
12+
--dry-run Don't actually write the lockfile
1313
-h, --help Print help
1414
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
1515
--color <WHEN> Coloring: auto, always, never

tests/testsuite/update.rs

+40
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,46 @@ fn update_aggressive() {
464464
.run();
465465
}
466466

467+
#[cargo_test]
468+
fn update_aggressive_conflicts_with_precise() {
469+
Package::new("log", "0.1.0").publish();
470+
Package::new("serde", "0.2.1").dep("log", "0.1").publish();
471+
472+
let p = project()
473+
.file(
474+
"Cargo.toml",
475+
r#"
476+
[package]
477+
name = "bar"
478+
version = "0.0.1"
479+
authors = []
480+
481+
[dependencies]
482+
serde = "0.2"
483+
"#,
484+
)
485+
.file("src/lib.rs", "")
486+
.build();
487+
488+
p.cargo("check").run();
489+
490+
Package::new("log", "0.1.1").publish();
491+
Package::new("serde", "0.2.2").dep("log", "0.1").publish();
492+
493+
p.cargo("update -p serde:0.2.1 --precise 0.2.2 --aggressive")
494+
.with_status(1)
495+
.with_stderr(
496+
"\
497+
error: the argument '--precise <PRECISE>' cannot be used with '--aggressive'
498+
499+
Usage: cargo[EXE] update --package [<SPEC>] --precise <PRECISE>
500+
501+
For more information, try '--help'.
502+
",
503+
)
504+
.run();
505+
}
506+
467507
// cargo update should respect its arguments even without a lockfile.
468508
// See issue "Running cargo update without a Cargo.lock ignores arguments"
469509
// at <https://github.com/rust-lang/cargo/issues/6872>.

0 commit comments

Comments
 (0)