Skip to content

Commit

Permalink
Auto merge of #12428 - epage:update, r=weihanglo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Aug 1, 2023
2 parents 772fd5f + 4fd0c3c commit baebd2b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
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

0 comments on commit baebd2b

Please sign in to comment.