forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In addition to `foo:1.2.3`, we now support `[email protected]` for pkgids. We are also making it the default way of rendering pkgid's for the user. With cargo-add in rust-lang#10472, we've decided to only use `@` in it and to add it as an alternative to `:` in the rest of cargo. `cargo-add` originally used `@`. When preparing it for merge, I switched to `:` to be consistent with pkgids. When discussing this, it was felt `@` has precedence in too many tools to switch to `:` but that we should instead switch pkgid's to use `@`, in a backwards compatible way. See also https://internals.rust-lang.org/t/feedback-on-cargo-add-before-its-merged/16024/26?u=epage
- Loading branch information
Showing
12 changed files
with
69 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,10 @@ impl PackageIdSpec { | |
/// "https://crates.io/foo", | ||
/// "https://crates.io/foo#1.2.3", | ||
/// "https://crates.io/foo#bar:1.2.3", | ||
/// "https://crates.io/foo#[email protected]", | ||
/// "foo", | ||
/// "foo:1.2.3", | ||
/// "[email protected]", | ||
/// ]; | ||
/// for spec in specs { | ||
/// assert!(PackageIdSpec::parse(spec).is_ok()); | ||
|
@@ -65,7 +67,7 @@ impl PackageIdSpec { | |
); | ||
} | ||
} | ||
let mut parts = spec.splitn(2, ':'); | ||
let mut parts = spec.splitn(2, [':', '@']); | ||
let name = parts.next().unwrap(); | ||
let version = match parts.next() { | ||
Some(version) => Some(version.to_semver()?), | ||
|
@@ -122,7 +124,7 @@ impl PackageIdSpec { | |
})?; | ||
match frag { | ||
Some(fragment) => { | ||
let mut parts = fragment.splitn(2, ':'); | ||
let mut parts = fragment.splitn(2, [':', '@']); | ||
let name_or_version = parts.next().unwrap(); | ||
match parts.next() { | ||
Some(part) => { | ||
|
@@ -268,7 +270,7 @@ impl PackageIdSpec { | |
} | ||
for id in ids { | ||
if version_cnt[id.version()] == 1 { | ||
msg.push_str(&format!("\n {}:{}", spec.name(), id.version())); | ||
msg.push_str(&format!("\n {}@{}", spec.name(), id.version())); | ||
} else { | ||
msg.push_str(&format!("\n {}", PackageIdSpec::from_package_id(*id))); | ||
} | ||
|
@@ -290,11 +292,11 @@ impl fmt::Display for PackageIdSpec { | |
} | ||
None => { | ||
printed_name = true; | ||
write!(f, "{}", self.name)? | ||
write!(f, "{}", self.name)?; | ||
} | ||
} | ||
if let Some(ref v) = self.version { | ||
write!(f, "{}{}", if printed_name { ":" } else { "#" }, v)?; | ||
write!(f, "{}{}", if printed_name { "@" } else { "#" }, v)?; | ||
} | ||
Ok(()) | ||
} | ||
|
@@ -329,10 +331,11 @@ mod tests { | |
|
||
#[test] | ||
fn good_parsing() { | ||
fn ok(spec: &str, expected: PackageIdSpec) { | ||
#[track_caller] | ||
fn ok(spec: &str, expected: PackageIdSpec, expected_rendered: &str) { | ||
let parsed = PackageIdSpec::parse(spec).unwrap(); | ||
assert_eq!(parsed, expected); | ||
assert_eq!(parsed.to_string(), spec); | ||
assert_eq!(parsed.to_string(), expected_rendered); | ||
} | ||
|
||
ok( | ||
|
@@ -342,6 +345,7 @@ mod tests { | |
version: None, | ||
url: Some(Url::parse("https://crates.io/foo").unwrap()), | ||
}, | ||
"https://crates.io/foo", | ||
); | ||
ok( | ||
"https://crates.io/foo#1.2.3", | ||
|
@@ -350,6 +354,7 @@ mod tests { | |
version: Some("1.2.3".to_semver().unwrap()), | ||
url: Some(Url::parse("https://crates.io/foo").unwrap()), | ||
}, | ||
"https://crates.io/foo#1.2.3", | ||
); | ||
ok( | ||
"https://crates.io/foo#bar:1.2.3", | ||
|
@@ -358,6 +363,16 @@ mod tests { | |
version: Some("1.2.3".to_semver().unwrap()), | ||
url: Some(Url::parse("https://crates.io/foo").unwrap()), | ||
}, | ||
"https://crates.io/foo#[email protected]", | ||
); | ||
ok( | ||
"https://crates.io/foo#[email protected]", | ||
PackageIdSpec { | ||
name: InternedString::new("bar"), | ||
version: Some("1.2.3".to_semver().unwrap()), | ||
url: Some(Url::parse("https://crates.io/foo").unwrap()), | ||
}, | ||
"https://crates.io/foo#[email protected]", | ||
); | ||
ok( | ||
"foo", | ||
|
@@ -366,6 +381,7 @@ mod tests { | |
version: None, | ||
url: None, | ||
}, | ||
"foo", | ||
); | ||
ok( | ||
"foo:1.2.3", | ||
|
@@ -374,6 +390,16 @@ mod tests { | |
version: Some("1.2.3".to_semver().unwrap()), | ||
url: None, | ||
}, | ||
"[email protected]", | ||
); | ||
ok( | ||
"[email protected]", | ||
PackageIdSpec { | ||
name: InternedString::new("foo"), | ||
version: Some("1.2.3".to_semver().unwrap()), | ||
url: None, | ||
}, | ||
"[email protected]", | ||
); | ||
} | ||
|
||
|
@@ -382,6 +408,9 @@ mod tests { | |
assert!(PackageIdSpec::parse("baz:").is_err()); | ||
assert!(PackageIdSpec::parse("baz:*").is_err()); | ||
assert!(PackageIdSpec::parse("baz:1.0").is_err()); | ||
assert!(PackageIdSpec::parse("baz@").is_err()); | ||
assert!(PackageIdSpec::parse("baz@*").is_err()); | ||
assert!(PackageIdSpec::parse("[email protected]").is_err()); | ||
assert!(PackageIdSpec::parse("https://baz:1.0").is_err()); | ||
assert!(PackageIdSpec::parse("https://#baz:1.0").is_err()); | ||
} | ||
|
@@ -397,5 +426,7 @@ mod tests { | |
assert!(!PackageIdSpec::parse("foo").unwrap().matches(bar)); | ||
assert!(PackageIdSpec::parse("foo:1.2.3").unwrap().matches(foo)); | ||
assert!(!PackageIdSpec::parse("foo:1.2.2").unwrap().matches(foo)); | ||
assert!(PackageIdSpec::parse("[email protected]").unwrap().matches(foo)); | ||
assert!(!PackageIdSpec::parse("[email protected]").unwrap().matches(foo)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -361,7 +361,7 @@ fn yank() { | |
.with_stderr( | ||
"\ | ||
[UPDATING] [..] | ||
[YANK] foo:0.1.0 | ||
[YANK] foo@0.1.0 | ||
", | ||
) | ||
.run(); | ||
|
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
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