-
Notifications
You must be signed in to change notification settings - Fork 144
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
New command: cargo-upgrade #138
Conversation
src/bin/upgrade/main.rs
Outdated
|
||
Options: | ||
-h, --help Print this message | ||
--dependency -d <dep> Dependency to update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can it be -d, --dependency <dep>
for consistency in usage?
Also, -V, --version
.
Same in README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it's worth mentioning here that upgrade will update dev, build and all target dependencies as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Though -d --dependency <dep>
(etc.) is probably more consistent with cargo add
/rm
,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, lets use -d --dependency <dep>
instead.
Looks good overall. Do you think we should somehow take into account overriding dependencies (I think we shouldn't)? |
README.md
Outdated
# Upgrade all dependencies | ||
$ cargo update | ||
# Upgrade libc and serde | ||
$ cargo update -d libc --dependency serde |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be cargo upgrade -d libc serde
instead?
Also typo: update -> upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so - the usage syntax is that you need one of -d
/--dependency
per dependency to be upgraded. This follows the pattern that cargo update
uses.
tests/test_manifest.rs
Outdated
"foo", | ||
"--manifest-path=tests/fixtures/manifest-invalid/Cargo.toml.sample"] => | ||
Error 1, | ||
"Command failed due to unhandled error: failed to parse datetime for key `invalid-section.key`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation here seems a bit off.
src/bin/upgrade/main.rs
Outdated
let manifest_path = manifest_path.as_ref().map(From::from); | ||
let mut manifest = Manifest::open(&manifest_path).unwrap(); | ||
|
||
// Look for dependencies in all three sections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: target dev-dependencies.
src/manifest.rs
Outdated
}) | ||
.collect::<Vec<_>>(); | ||
|
||
// ... or in `target.<target name>.(dev-)dependencies`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like target build-dependencies is also a thing.
@bjgill Thank you! |
@killercup - do you want to give this a look? Otherwise, I'll merge on Monday |
Thanks for the ping! I'll try to review it this weekend.
I originally also planned to release a 0.2 on the weekend/early next week,
so it'd be nice to have this in.
Benjamin Gill <notifications@github.com> schrieb am Do., 6. Juli 2017 um
20:18 Uhr:
… @killercup <https://github.com/killercup> - do you want to give this a
look? Otherwise, I'll merge on Monday
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#138 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOX6rtmeU9FEfUR-e4gE5j735l6LXMks5sLSTpgaJpZM4OOsLP>
.
|
I've now added the change to switch Once merged, this will be straightforwardly extensible to add proper workspace support. @killercup - were you wanting to review this? |
Sorry, I'm sooo behind on my reviews. Quick thought: Instead of using cargo as a library (that includes a truckload of dependencies I assume), we can also run |
Yes. As the AppVeyor CI is showing, the non-Rust dependencies of |
In fact, I think the switch to I've reset to the commit prior to the introduction of EDIT: for future reference, the removed commits can be found in bjgill#2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I've finally read through this. Very nice! I left a few inline comments, but nothing major. Is there a test for updating a dependency only available in one target?
Feel free to merge this once you think it's good to go!
src/bin/upgrade/main.rs
Outdated
// Not a version dependency if the `git` or `path` keys are present. | ||
!(table.contains_key("git") || table.contains_key("path")) | ||
}) | ||
.unwrap_or(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment seems redundant as the code says basically the same thing. I also think I'd nowadays write this as
if let Some(table) = dep.as_table() {
!table.contains_key("git") && !table.contains_key("path")
} else {
true
}
src/bin/upgrade/main.rs
Outdated
}) | ||
.filter(|&(_name, old_value)| is_version_dependency(old_value)) | ||
.map(|(name, _old_value)| { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✂️
src/bin/upgrade/main.rs
Outdated
|
||
Ok(()) | ||
}) | ||
.collect::<Result<Vec<_>, Box<Error>>>()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are collecting this into a Vec… just to drop it? Seems weird. Better use an inner for-loop with the body of the map (this way the ?
will return in the fn scope)
src/manifest.rs
Outdated
if let Some(segment) = path.pop_front() { | ||
let value = match *input | ||
.entry(segment.to_owned()) | ||
.or_insert_with(|| toml::Value::Table(BTreeMap::new())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard to read. Can you give the thing you are matching over its own binding and keep the match head single-line?
src/manifest.rs
Outdated
} | ||
} | ||
|
||
descend(&mut self.data, table_path.into_iter().collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done.
src/manifest.rs
Outdated
/// Descend into a manifest until the required table is found. | ||
fn descend<'a>( | ||
input: &'a mut BTreeMap<String, toml::Value>, | ||
mut path: VecDeque<&String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid allocation?
I think, if we make path: &[String]
, then
if let Some(segment) = path.pop_front() {
can be replaced with if !path.is_empty() { let segment = path[0];
and descend(value, path)
with descend(value, &path[1..])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, using sub slices is pretty clever :)
(But don't go out your way to optimize stuff like this; this whole project is in no way performance critical code!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is quite nice.
@killercup and @ordian - thanks. The Appveyor failures are entirely spurious - it looks as if the revocation server they use is currently down. I'll squash and pass to bors to merge in. |
This adds `cargo upgrade` as a more fully featured replacement for `cargo add --update-only`. Usage: ```plain Upgrade all dependencies in a manifest file to the latest version. Usage: cargo upgrade [--dependency <dep>...] [--manifest-path <path>] cargo upgrade (-h | --help) cargo upgrade (-V | --version) Options: -d --dependency <dep> Specific dependency to upgrade. If this option is used, only the specified dependencies will be upgraded. --manifest-path <path> Path to the manifest to upgrade. -h --help Show this help page. -V --version Show version. Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are supported. Git/path dependencies will be ignored. ``` Resolves killercup#74.
bors r+ |
138: New command: cargo-upgrade r=bjgill This adds `cargo upgrade` as a more fully featured replacement for `cargo add --update-only`. Usage: ```plain Upgrade all dependencies in a manifest file to the latest version. Usage: cargo upgrade [--dependency <dep>...] [--manifest-path <path>] cargo upgrade (-h | --help) cargo upgrade (-V | --version) Options: -d --dependency <dep> Specific dependency to upgrade. If this option is used, only the specified dependencies will be upgraded. --manifest-path <path> Path to the manifest to upgrade. -h --help Show this help page. -V --version Show version. Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are supported. Git/path dependencies will be ignored. ``` Resolves #74. Next steps (beyond this PR; probably not in v0.2) will be: * Workspace support * interactive 'check mode' * Use `cargo` to parse the manifests (I'll squash prior to merging)
Build failed |
Yeah, for most rust projects appveyor seems quiet slow and fragile… feel
free to remove it from bors' config.
bors[bot] <notifications@github.com> schrieb am Do. 20. Juli 2017 um 01:25:
… Build failed
- continuous-integration/appveyor/branch
<https://ci.appveyor.com/project/killercup/cargo-edit/build/1.0.26>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#138 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOX9gkeT2obh0XeGdOjInNGWoupSPzks5sPpB1gaJpZM4OOsLP>
.
|
It's currently too unreliable
Ok. I've raised #139 to cover re-instating Appveyor in bors bors r+ |
138: New command: cargo-upgrade r=bjgill This adds `cargo upgrade` as a more fully featured replacement for `cargo add --update-only`. Usage: ```plain Upgrade all dependencies in a manifest file to the latest version. Usage: cargo upgrade [--dependency <dep>...] [--manifest-path <path>] cargo upgrade (-h | --help) cargo upgrade (-V | --version) Options: -d --dependency <dep> Specific dependency to upgrade. If this option is used, only the specified dependencies will be upgraded. --manifest-path <path> Path to the manifest to upgrade. -h --help Show this help page. -V --version Show version. Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are supported. Git/path dependencies will be ignored. ``` Resolves #74. Next steps (beyond this PR; probably not in v0.2) will be: * Workspace support * interactive 'check mode' * Use `cargo` to parse the manifests (I'll squash prior to merging)
Build succeeded |
This adds
cargo upgrade
as a more fully featured replacement forcargo add --update-only
.Usage:
Resolves #74.
Next steps (beyond this PR; probably not in v0.2) will be:
cargo
to parse the manifests(I'll squash prior to merging)