-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #10597 - epage:yank, r=ehuss
feat(yank): Support foo@version like cargo-add ### What does this PR try to resolve? In #10472, cargo-add was merged with support for an inline version syntax of `cargo add foo@version`. That also served as the change proposal for extending that syntax to `cargo yank` for convenience and consistency. ### How should we test and review this PR? Documentation updates are split into their own commit to not clog up browsing the code. The ops API is generic enough that this is implemented purely in the command. For now, the `foo@version` syntax parser is being left in the command, rather than being shared, as we see how the behavior of these different parsers diverge for their target needs to see what makes sense for refactoring. See also The Rule of Three - This doesn't use the full `pkgid` syntax (modified in #10582) because that allows syntax that is unsupported here. - This doesn't use `cargo-add`s parser because that is for version reqs. Tests were added for various combinations of flags and behavior. ### Additional information The major difference is that `cargo-add` is specifying a version-req while `cargo-yank` is specifying a version. This was originally discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Multiple.20ways.20of.20specifying.20versions) and there seemed to be a desire to have one syntax rather than the user thinking about a syntax per type of version (which users won't always think about). See also #10582 which extended the pkgid spec syntax and has some more discussion on this general trend. `cargo-install` will be updated in a subsequent PR.
- Loading branch information
Showing
6 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ fn setup(name: &str, version: &str) { | |
} | ||
|
||
#[cargo_test] | ||
fn simple() { | ||
fn explicit_version() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
|
@@ -46,3 +46,116 @@ Caused by: | |
) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn inline_version() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank [email protected] --token sekrit").run(); | ||
|
||
p.cargo("yank --undo [email protected] --token sekrit") | ||
.with_status(101) | ||
.with_stderr( | ||
" Updating `[..]` index | ||
Unyank [email protected] | ||
error: failed to undo a yank from the registry at file:///[..] | ||
Caused by: | ||
EOF while parsing a value at line 1 column 0", | ||
) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn version_required() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank foo --token sekrit") | ||
.with_status(101) | ||
.with_stderr("error: `--version` is required") | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn inline_version_without_name() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank @0.0.1 --token sekrit") | ||
.with_status(101) | ||
.with_stderr("error: missing crate name for `@0.0.1`") | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn inline_and_explicit_version() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[project] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank [email protected] --version 0.0.1 --token sekrit") | ||
.with_status(101) | ||
.with_stderr("error: cannot specify both `@0.0.1` and `--version`") | ||
.run(); | ||
} |