diff options
author | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-09-22 09:13:47 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-09-22 09:13:47 +0300 |
commit | 5275e6e1392c5f0f7a10949d08ef1b76d1f826b1 (patch) | |
tree | 921ca4d476b5f0c8e7736b2f28fcb1735f25a235 | |
parent | edca1d46f615c52129d1ec6e2fc8b9236197d4cb (diff) | |
download | missing-dependencies-5275e6e1392c5f0f7a10949d08ef1b76d1f826b1.tar.gz |
use tables tho show lists of problems
Sponsored-by: pep.foundation
-rw-r--r-- | Cargo.lock | 54 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 100 |
3 files changed, 114 insertions, 41 deletions
@@ -41,6 +41,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] +name = "bytecount" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" + +[[package]] name = "camino" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -130,6 +136,12 @@ dependencies = [ ] [[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -207,6 +219,7 @@ dependencies = [ "pretty_env_logger", "regex", "semver", + "tabled", ] [[package]] @@ -222,6 +235,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] +name = "papergrid" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453cf71f2a37af495a1a124bf30d4d7469cfbea58e9f2479be9d222396a518a2" +dependencies = [ + "bytecount", + "fnv", + "unicode-width", +] + +[[package]] name = "pretty_env_logger" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -360,6 +384,30 @@ dependencies = [ ] [[package]] +name = "tabled" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5b2f8c37d26d87d2252187b0a45ea3cbf42baca10377c7e7eaaa2800fa9bf97" +dependencies = [ + "papergrid", + "tabled_derive", + "unicode-width", +] + +[[package]] +name = "tabled_derive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9ee618502f497abf593e1c5c9577f34775b111480009ffccd7ad70d23fcaba8" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -381,6 +429,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" [[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -13,3 +13,4 @@ log = "0.4.17" pretty_env_logger = "0.4.0" regex = "1.6.0" semver = "1.0.12" +tabled = "0.8.0" diff --git a/src/main.rs b/src/main.rs index e904bd0..f527163 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ use clap::Parser; use log::{debug, error, info, trace}; use semver::{Version, VersionReq}; use std::collections::HashMap; -use std::fmt; use std::fs::read; use std::path::{Path, PathBuf}; +use tabled::{Style, Table, Tabled}; fn main() { if let Err(e) = fallible_main() { @@ -62,11 +62,11 @@ fn fallible_main() -> anyhow::Result<()> { "crate {} is packaged, but version doesn't satisfy {}", c.orig_name, c.version ); - problems.push(Problem::MissingVersion( - c.orig_name.clone(), - req.clone(), - c.version.clone(), - )); + problems.push(Problem::MissingVersion(MissingVersion { + name: c.orig_name.clone(), + req: req.clone(), + version: c.version.clone(), + })); } else { info!( "crate {} is packaged and version satisfies {}", @@ -75,7 +75,10 @@ fn fallible_main() -> anyhow::Result<()> { } } else { info!("crate {} is not packaged at all", name); - problems.push(Problem::MissingCrate(name.clone(), req.clone())); + problems.push(Problem::MissingCrate(MissingCrate { + name: name.clone(), + req: req.clone(), + })); } } @@ -85,34 +88,42 @@ fn fallible_main() -> anyhow::Result<()> { Ok(()) } else { problems.sort_by_key(|p| match p { - Problem::MissingCrate(name, _) => name.clone(), - Problem::MissingVersion(name, _, _) => name.clone(), + Problem::MissingCrate(x) => x.name.clone(), + Problem::MissingVersion(x) => x.name.clone(), }); - let versions: Vec<&Problem> = problems + let versions: Vec<&MissingVersion> = problems .iter() - .filter(|p| matches!(p, Problem::MissingVersion(_, _, _))) + .filter_map(|p| match p { + Problem::MissingVersion(x) => Some(x), + _ => None, + }) .collect(); - if !versions.is_empty() { - println!("crates with required version missing:"); - for v in versions { - if let Problem::MissingVersion(name, req, got) = v { - println!(" {} {} (require {})", name, got, req); - } - } - } - let crates: Vec<&Problem> = problems + let crates: Vec<&MissingCrate> = problems .iter() - .filter(|p| matches!(p, Problem::MissingCrate(__, _))) + .filter_map(|p| match p { + Problem::MissingCrate(x) => Some(x), + _ => None, + }) .collect(); + + let got_versions = !versions.is_empty(); + if got_versions { + let table = Table::new(versions).with(Style::modern()); + println!("Table: Packaged version is not what is required"); + println!(); + println!("{}", table.to_string()); + } + if !crates.is_empty() { - println!("crates missing entirely:"); - for c in crates { - if let Problem::MissingCrate(name, req) = c { - println!(" {} {}", name, req); - } + if got_versions { + println!(); } + let table = Table::new(crates).with(Style::modern()); + println!("Table: Required crate is not packaged at all"); + println!(); + println!("{}", table.to_string()); } Err(anyhow!( @@ -220,23 +231,30 @@ impl Crates { #[derive(Debug, Clone, Eq, PartialEq)] enum Problem { - MissingCrate(String, VersionReq), - MissingVersion(String, VersionReq, Version), + MissingCrate(MissingCrate), + MissingVersion(MissingVersion), } -impl fmt::Display for Problem { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Self::MissingCrate(name, req) => write!(f, "missing-entirely {} {}", name, req), - Self::MissingVersion(name, req, got) => { - write!( - f, - "missing-version: crate {} want {} got {}", - name, req, got - ) - } - } - } +#[derive(Debug, Clone, Eq, PartialEq, Tabled)] +struct MissingCrate { + #[tabled(rename = "Crate")] + name: String, + + #[tabled(rename = "Required version")] + req: VersionReq, +} + +#[derive(Debug, Clone, Eq, PartialEq, Tabled)] +#[tabled(rename = "Crates for which a packaged version is too old")] +struct MissingVersion { + #[tabled(rename = "Crate")] + name: String, + + #[tabled(rename = "Required version")] + req: VersionReq, + + #[tabled(rename = "Packaged version")] + version: Version, } #[derive(Default, Debug)] |