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): Make -p more convenient by being positional #12545

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(update): Improve error on bad argument order
This is inspired by `cargo install`
  • Loading branch information
epage committed Aug 23, 2023
commit dc3722254d6c6ea36c6d0162f2957a580907a147
13 changes: 12 additions & 1 deletion src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
use crate::command_prelude::*;

use anyhow::anyhow;
use cargo::ops::{self, UpdateOptions};
use cargo::util::print_available_packages;

Expand Down Expand Up @@ -58,11 59,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
} else {
"package2"
};
let to_update = values(args, to_update);
for crate_name in to_update.iter() {
if let Some(toolchain) = crate_name.strip_prefix(" ") {
return Err(anyhow!(
"invalid character ` ` in package name: ` {toolchain}`
Use `cargo {toolchain} update` if you meant to use the `{toolchain}` toolchain."
)
.into());
}
}

let update_opts = UpdateOptions {
aggressive: args.flag("aggressive"),
precise: args.get_one::<String>("precise").map(String::as_str),
to_update: values(args, to_update),
to_update,
dry_run: args.dry_run(),
workspace: args.flag("workspace"),
config,
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_update/mod.rs
Original file line number Diff line number Diff line change
@@ -1 1,2 @@
mod help;
mod toolchain_pkgname;
5 changes: 5 additions & 0 deletions tests/testsuite/cargo_update/toolchain_pkgname/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
[package]
name = "test"
version = "0.1.0"

[dependencies]
3 changes: 3 additions & 0 deletions tests/testsuite/cargo_update/toolchain_pkgname/in/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
fn main() {
println!("Hello, world!");
}
19 changes: 19 additions & 0 deletions tests/testsuite/cargo_update/toolchain_pkgname/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

#[cargo_test]
fn case() {
let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("update")
.arg(" stable")
.current_dir(cwd)
.assert()
.code(101)
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
2 changes: 2 additions & 0 deletions tests/testsuite/cargo_update/toolchain_pkgname/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
error: invalid character ` ` in package name: ` stable`
Use `cargo stable update` if you meant to use the `stable` toolchain.
Empty file.
Loading