Skip to content

Commit

Permalink
feat(upgrade): Provide table view for upgrades
Browse files Browse the repository at this point in the history
This provides a `cargo outdated`-like UI, reducing the need for one
extra tool and helps raise visibility into cargo-upgrades decisions in a
pretty way (compared to lines and lines of warnings).

Fixes killercup#750
  • Loading branch information
epage committed Jul 27, 2022
1 parent 36dbb19 commit 52b100b
Show file tree
Hide file tree
Showing 53 changed files with 572 additions and 298 deletions.
377 changes: 243 additions & 134 deletions src/bin/upgrade/upgrade.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/lib.rs
Expand Up @@ -37,6 +37,7 @@ pub use manifest::{find, get_dep_version, set_dep_version, LocalManifest, Manife
pub use metadata::{manifest_from_pkgid, resolve_manifests, workspace_members};
pub use registry::registry_url;
pub use util::{
colorize_stderr, shell_note, shell_print, shell_status, shell_warn, Color, ColorChoice,
colorize_stderr, shell_note, shell_print, shell_status, shell_warn, shell_write_stderr, Color,
ColorChoice,
};
pub use version::{upgrade_requirement, VersionExt};
11 changes: 11 additions & 0 deletions src/util.rs
Expand Up @@ -48,3 +48,14 @@ pub fn shell_warn(message: &str) -> CargoResult<()> {
pub fn shell_note(message: &str) -> CargoResult<()> {
shell_print("note", message, Color::Cyan, false)
}

/// Print a part of a line with formatting
pub fn shell_write_stderr(fragment: impl std::fmt::Display, spec: &ColorSpec) -> CargoResult<()> {
let color_choice = colorize_stderr();
let mut output = StandardStream::stderr(color_choice);

output.set_color(spec)?;
write!(output, "{}", fragment)?;
output.reset()?;
Ok(())
}
6 changes: 4 additions & 2 deletions tests/cargo-upgrade/alt_registry/stderr.log
@@ -1,5 +1,7 @@
Updating '[ROOTURL]/registry' index
Checking none's dependencies
Updating '[ROOTURL]/alternative-registry' index
Upgrading my-package1: v0.1.1 -> v99999.0.0
Upgrading my-package2: v0.2 -> v99999.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package1 0.1.1 - 99999.0.0 99999.0.0
my-package2 0.2 - 99999.0.0 99999.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/dry_run/stderr.log
@@ -1,4 +1,6 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
warning: aborting upgrade due to dry run
32 changes: 17 additions & 15 deletions tests/cargo-upgrade/exclude_dep/stderr.log
@@ -1,18 +1,20 @@
Updating '[ROOTURL]/registry' index
Checking None's dependencies
warning: ignoring docopt, excluded by user
Upgrading pad: v0.1 -> v99999.0
Upgrading serde_json: v1.0 -> v99999.0
Upgrading syn: v0.11.10 -> v99999.0.0
Upgrading tar: v0.4 -> v99999.0
Upgrading ftp: v2.2.1 -> v99999.0.0
Upgrading te: v0.1.5 -> v99999.0.0
Upgrading semver: v0.7 -> v99999.0
Upgrading rn: v0.1 -> v99999.0
Upgrading assert_cli: v0.2.0 -> v99999.0.0
Upgrading tempdir: v0.3 -> v99999.0
warning: ignoring serde, source is https://github.com/serde-rs/serde.git
Upgrading openssl: v0.9 -> v99999.0
Upgrading rget: v0.3.0 -> v99999.0.0
Upgrading geo: v0.7.0 -> v99999.0.0
Upgrading ftp: v2.2.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
pad 0.1 - 99999.0.0 99999.0
serde_json 1.0 - 99999.0.0 99999.0
syn 0.11.10 - 99999.0.0 99999.0.0
tar 0.4 - 99999.0.0 99999.0
ftp 2.2.1 - 99999.0.0 99999.0.0
te 0.1.5 - 99999.0.0 99999.0.0
semver 0.7 - 99999.0.0 99999.0
rn 0.1 - 99999.0.0 99999.0
assert_cli 0.2.0 - 99999.0.0 99999.0.0
tempdir 0.3 - 99999.0.0 99999.0
serde 1.0 - - 1.0
openssl 0.9 - 99999.0.0 99999.0
rget 0.3.0 - 99999.0.0 99999.0.0
geo 0.7.0 - 99999.0.0 99999.0.0
ftp 2.2.1 - 99999.0.0 99999.0.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/exclude_renamed/stderr.log
@@ -1,5 +1,7 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
warning: ignoring te, renamed dependencies are pinned
warning: ignoring rx, excluded by user
name old req locked latest new req note
==== ======= ====== ====== ======= ====
te 0.1.5 - 99999.0.0 0.1.5 pinned
note: Re-run with `--pinned` to upgrade pinned version requirements
6 changes: 4 additions & 2 deletions tests/cargo-upgrade/implicit_prerelease/stderr.log
@@ -1,4 +1,6 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading unrelated-crate: v1.0 -> v99999.0
Upgrading my-package: v0.1.1-alpha.1 -> v99999.1.0-alpha.1
name old req locked latest new req note
==== ======= ====== ====== ======= ====
unrelated-crate 1.0 - 99999.0.0 99999.0
my-package 0.1.1-alpha.1 - 99999.1.0-alpha.1 99999.1.0-alpha.1
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/locked/stderr.log
@@ -1,4 +1,6 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
Error: cannot upgrade due to `--locked`
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/optional_dep/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
20 changes: 11 additions & 9 deletions tests/cargo-upgrade/pinned/stderr.log
@@ -1,13 +1,15 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading default: v1.0 -> v99999.0
warning: ignoring exact, version (=2.0) is pinned
warning: ignoring lessthan, version (<0.4) is pinned
warning: ignoring lessorequal, version (<=3.0) is pinned
Upgrading caret: ^3.0 -> ^99999.0
Upgrading tilde: ~4.1.0 -> ~99999.0.0
warning: ignoring greaterthan, version (>2.0) is compatible with 99999.0.0
warning: ignoring greaterorequal, version (>=2.1.0) is compatible with 99999.0.0
Upgrading wildcard: v3.* -> v99999.*
name old req locked latest new req note
==== ======= ====== ====== ======= ====
default 1.0 - 99999.0.0 99999.0
exact =2.0 - 99999.0.0 =2.0 pinned
lessthan <0.4 - 99999.0.0 <0.4 pinned
lessorequal <=3.0 - 99999.0.0 <=3.0 pinned
caret ^3.0 - 99999.0.0 ^99999.0
tilde ~4.1.0 - 99999.0.0 ~99999.0.0
greaterthan >2.0 - 99999.0.0 >2.0 compatible
greaterorequal >=2.1.0 - 99999.0.0 >=2.1.0 compatible
wildcard 3.* - 99999.0.0 99999.*
note: Re-run with `--pinned` to upgrade pinned version requirements
note: Re-run with `--to-lockfile` to upgrade compatible version requirements
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/preserve_precision_major/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0 -> v99999
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0 - 99999.0.0 99999
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/preserve_precision_minor/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1 -> v99999.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1 - 99999.0.0 99999.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/preserve_precision_patch/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/preserves_inline_table/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/preserves_std_table/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/single_dep/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
6 changes: 4 additions & 2 deletions tests/cargo-upgrade/skip_compatible/stderr.log
@@ -1,5 +1,7 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading test_breaking: v0.1 -> v0.2
warning: ignoring test_nonbreaking, version (0.1) is compatible with 0.1.1
name old req locked latest new req note
==== ======= ====== ====== ======= ====
test_breaking 0.1 - 0.2.0 0.2
test_nonbreaking 0.1 - 0.1.1 0.1 compatible
note: Re-run with `--to-lockfile` to upgrade compatible version requirements
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/specified/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading my-package1: v0.1 -> v99999.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package1 0.1 - 99999.0.0 99999.0
18 changes: 13 additions & 5 deletions tests/cargo-upgrade/to_lockfile/stderr.log
@@ -1,9 +1,17 @@
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
Upgrading three: v0.1.0 -> v0.1.5
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 0.2.3+my-package 99999.0.0 0.2.3
three 0.1.0 0.1.5 - 0.1.5
Checking three's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 0.2.3+my-package 99999.0.0 0.2.3
Checking two's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 0.2.3+my-package 99999.0.0 0.2.3
Checking four's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 0.2.3+my-package 99999.0.0 0.2.3
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/to_version/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading docopt: v0.8.0 -> v1000000.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
docopt 0.8.0 - 99999.0.0 1000000.0.0
17 changes: 13 additions & 4 deletions tests/cargo-upgrade/upgrade_all/stderr.log
@@ -1,10 +1,19 @@
The flag `--all` has been deprecated in favor of `--workspace`
Updating '[ROOTURL]/registry' index
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
three 0.1.0 - - 0.1.0
Checking three's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking two's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking four's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
33 changes: 18 additions & 15 deletions tests/cargo-upgrade/upgrade_everything/stderr.log
@@ -1,17 +1,20 @@
Updating '[ROOTURL]/registry' index
Checking None's dependencies
Upgrading docopt: v0.8 -> v99999.0
Upgrading pad: v0.1 -> v99999.0
Upgrading serde_json: v1.0 -> v99999.0
Upgrading syn: v0.11.10 -> v99999.0.0
Upgrading tar: v0.4 -> v99999.0
Upgrading ftp: v2.2.1 -> v99999.0.0
Upgrading te: v0.1.5 -> v99999.0.0
Upgrading semver: v0.7 -> v99999.0
Upgrading rn: v0.1 -> v99999.0
Upgrading assert_cli: v0.2.0 -> v99999.0.0
Upgrading tempdir: v0.3 -> v99999.0
Upgrading openssl: v0.9 -> v99999.0
Upgrading rget: v0.3.0 -> v99999.0.0
Upgrading geo: v0.7.0 -> v99999.0.0
Upgrading ftp: v2.2.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
docopt 0.8 - 99999.0.0 99999.0
pad 0.1 - 99999.0.0 99999.0
serde_json 1.0 - 99999.0.0 99999.0
syn 0.11.10 - 99999.0.0 99999.0.0
tar 0.4 - 99999.0.0 99999.0
ftp 2.2.1 - 99999.0.0 99999.0.0
te 0.1.5 - 99999.0.0 99999.0.0
semver 0.7 - 99999.0.0 99999.0
rn 0.1 - 99999.0.0 99999.0
assert_cli 0.2.0 - 99999.0.0 99999.0.0
tempdir 0.3 - 99999.0.0 99999.0
serde 1.0 - - 1.0
openssl 0.9 - 99999.0.0 99999.0
rget 0.3.0 - 99999.0.0 99999.0.0
geo 0.7.0 - 99999.0.0 99999.0.0
ftp 2.2.1 - 99999.0.0 99999.0.0
6 changes: 4 additions & 2 deletions tests/cargo-upgrade/upgrade_renamed/stderr.log
@@ -1,4 +1,6 @@
Updating '[ROOTURL]/registry' index
Checking cargo-list-test-fixture's dependencies
Upgrading m1: v0.1.1 -> v99999.0.0
Upgrading m2: v0.2 -> v99999.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
m1 0.1.1 - 99999.0.0 99999.0.0
m2 0.2 - 99999.0.0 99999.0
17 changes: 13 additions & 4 deletions tests/cargo-upgrade/upgrade_workspace/stderr.log
@@ -1,9 +1,18 @@
Updating '[ROOTURL]/registry' index
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
three 0.1.0 - - 0.1.0
Checking three's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking two's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking four's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
17 changes: 13 additions & 4 deletions tests/cargo-upgrade/virtual_manifest/stderr.log
@@ -1,9 +1,18 @@
Updating '[ROOTURL]/registry' index
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
three 0.1.0 - - 0.1.0
Checking three's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking two's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
Checking four's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
4 changes: 3 additions & 1 deletion tests/cargo-upgrade/workspace_member_cwd/stderr.log
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking one's dependencies
Upgrading my-package: v0.1.1 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.1.1 - 99999.0.0 99999.0.0
@@ -1,3 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
my-package 0.2.0 - 99999.0.0 99999.0.0
6 changes: 4 additions & 2 deletions tests/cmd/upgrade/alt_registry.toml
Expand Up @@ -4,8 +4,10 @@ status = "success"
stdout = ""
stderr = """
Checking none's dependencies
Upgrading toml_edit: v0.1.5 -> v99999.0.0
Upgrading regex: v0.2 -> v99999.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
toml_edit 0.1.5 - 99999.0.0 99999.0.0
regex 0.2 - 99999.0.0 99999.0
"""
fs.sandbox = true

Expand Down
4 changes: 3 additions & 1 deletion tests/cmd/upgrade/dry_run.toml
Expand Up @@ -4,7 +4,9 @@ status = "success"
stdout = ""
stderr = """
Checking cargo-list-test-fixture's dependencies
Upgrading docopt: v0.8.0 -> v99999.0.0
name old req locked latest new req note
==== ======= ====== ====== ======= ====
docopt 0.8.0 - 99999.0.0 99999.0.0
warning: aborting upgrade due to dry run
"""
fs.sandbox = true
Expand Down

0 comments on commit 52b100b

Please sign in to comment.