diff --git a/Cargo.lock b/Cargo.lock index 7ea9157..c0cb3be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,12 +65,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - [[package]] name = "autocfg" version = "1.1.0" @@ -135,10 +129,10 @@ dependencies = [ name = "cargo-attribution" version = "0.6.0" dependencies = [ - "anyhow", "bytes", "cargo_metadata", "clap", + "color-eyre", "reqwest", "serde", "spdx", @@ -225,6 +219,19 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -272,6 +279,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "eyre" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "2.0.1" @@ -477,6 +494,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -671,6 +694,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parking_lot" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index e8e2bd9..4935b7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,10 @@ keywords = ["cli", "attribution", "credits", "license"] categories = ["command-line-utilities"] [dependencies] -anyhow = "1.0.75" bytes = "1.5.0" cargo_metadata = "0.18.1" clap = { version = "4.4.6", features = ["derive"] } +color-eyre = { version = "0.6.2", default-features = false } reqwest = "0.11.22" serde = { version = "1.0.189", features = ["derive"] } spdx = "0.10.2" diff --git a/attribution/dependencies.toml b/attribution/dependencies.toml index 0b841eb..8396f43 100644 --- a/attribution/dependencies.toml +++ b/attribution/dependencies.toml @@ -59,14 +59,6 @@ notices = ["Copyright (c) 2015 Josh Triplett, 2022 The rust-cli Developers"] repository = "https://github.com/rust-cli/anstyle.git" homepage = "https://github.com/rust-cli/anstyle" -[[dependencies]] -name = "anyhow" -version = "1.0.75" -description = "Flexible concrete Error type built on std::error::Error" -license = "MIT OR Apache-2.0" -authors = ["David Tolnay "] -repository = "https://github.com/dtolnay/anyhow" - [[dependencies]] name = "autocfg" version = "1.1.0" @@ -228,6 +220,14 @@ license = "MIT OR Apache-2.0" notices = ["Copyright (c) 2015-2022 Kevin B. Knapp and Clap Contributors"] repository = "https://github.com/clap-rs/clap/tree/master/clap_lex" +[[dependencies]] +name = "color-eyre" +version = "0.6.2" +description = "An error report handler for panics and eyre::Reports for colorful, consistent, and well formatted error reports for all kinds of errors." +license = "MIT OR Apache-2.0" +authors = ["Jane Lusby "] +repository = "https://github.com/yaahc/color-eyre" + [[dependencies]] name = "colorchoice" version = "1.0.0" @@ -281,6 +281,17 @@ notices = ["Copyright (c) 2014 Chris Wong"] authors = ["Chris Wong "] repository = "https://github.com/lambda-fairy/rust-errno" +[[dependencies]] +name = "eyre" +version = "0.6.8" +description = "Flexible concrete Error Reporting type built on std::error::Error with customizable Reports" +license = "MIT OR Apache-2.0" +authors = [ + "David Tolnay ", + "Jane Lusby ", +] +repository = "https://github.com/yaahc/eyre" + [[dependencies]] name = "fastrand" version = "2.0.1" @@ -530,6 +541,16 @@ notices = ["Copyright (c) 2013-2022 The rust-url developers"] authors = ["The rust-url developers"] repository = "https://github.com/servo/rust-url/" +[[dependencies]] +name = "indenter" +version = "0.3.3" +description = """ +A formatter wrapper that indents the text, designed for error display impls +""" +license = "MIT OR Apache-2.0" +authors = ["Jane Lusby "] +repository = "https://github.com/yaahc/indenter" + [[dependencies]] name = "indexmap" version = "1.9.3" @@ -749,6 +770,15 @@ authors = [ ] repository = "https://github.com/sfackler/rust-openssl" +[[dependencies]] +name = "owo-colors" +version = "3.5.0" +description = "Zero-allocation terminal colors that'll make people go owo" +license = "MIT" +notices = ["Copyright (c) 2020 - present The owo-colors Developers"] +authors = ["jam1garner <8260240+jam1garner@users.noreply.github.com>"] +repository = "https://github.com/jam1garner/owo-colors" + [[dependencies]] name = "parking_lot" version = "0.12.1" diff --git a/src/lib.rs b/src/lib.rs index 8abf7de..7dcd78e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,13 +3,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use color_eyre::Result; use std::{fs, path::Path}; pub mod licenses; pub mod metadata; pub mod serialize; -pub fn recreate_folder(path: &Path) -> anyhow::Result<()> { +pub fn recreate_folder(path: &Path) -> Result<()> { if path.try_exists()? { fs::remove_dir_all(path)?; } @@ -19,7 +20,7 @@ pub fn recreate_folder(path: &Path) -> anyhow::Result<()> { Ok(()) } -pub fn create_folder(path: &Path) -> anyhow::Result<()> { +pub fn create_folder(path: &Path) -> Result<()> { if path.try_exists()? { return Ok(()); } diff --git a/src/licenses.rs b/src/licenses.rs index 852566b..910e6e1 100644 --- a/src/licenses.rs +++ b/src/licenses.rs @@ -3,10 +3,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::path::PathBuf; - use bytes::Bytes; +use color_eyre::Result; use reqwest::{self, Url}; +use std::path::PathBuf; use tokio::{fs::File, io::AsyncWriteExt, task}; use crate::metadata::DependencyData; @@ -18,18 +18,18 @@ pub struct LicenseData { } impl LicenseData { - pub async fn get_license_content(&self) -> anyhow::Result { + pub async fn get_license_content(&self) -> Result { let content = reqwest::get(self.url.clone()).await?.bytes().await?; Ok(content) } - pub async fn create_license_file(&self, content: Bytes) -> anyhow::Result<()> { + pub async fn create_license_file(&self, content: Bytes) -> Result<()> { let mut file = File::create(&self.path).await?; file.write_all(&content).await?; Ok(()) } - pub async fn generate_license(&self) -> anyhow::Result<()> { + pub async fn generate_license(&self) -> Result<()> { println!("Downloading {}", self.name); let content = self.get_license_content().await?; self.create_license_file(content).await?; @@ -38,10 +38,7 @@ impl LicenseData { } } -pub async fn generate_licenses( - crates_data: &[DependencyData], - output_dir: PathBuf, -) -> anyhow::Result<()> { +pub async fn generate_licenses(crates_data: &[DependencyData], output_dir: PathBuf) -> Result<()> { let mut licenses = crates_data .iter() .flat_map(|c| c.licenses.clone()) diff --git a/src/main.rs b/src/main.rs index 2a17d3c..7c69a49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,12 @@ use cargo_attribution::{ }; use cargo_metadata::{CargoOpt, MetadataCommand}; use clap::Parser; +use color_eyre::eyre::Result; #[tokio::main] -async fn main() -> anyhow::Result<()> { +async fn main() -> Result<()> { + color_eyre::install()?; + let CargoCli::Attribution(Args { manifest_path, current_dir, diff --git a/src/metadata.rs b/src/metadata.rs index 73c9e55..4f8a720 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -5,8 +5,8 @@ use std::fs; -use anyhow::Context; use cargo_metadata::{DependencyKind, Metadata, Package}; +use color_eyre::{eyre::ContextCompat, Result}; use serde::Serialize; use spdx::Expression; @@ -50,11 +50,11 @@ impl DependencyData { } impl DependencyData { - pub fn get_license_notices(&mut self, package: &Package) -> anyhow::Result<()> { + pub fn get_license_notices(&mut self, package: &Package) -> Result<()> { let parent = package .manifest_path .parent() - .context("Not manifest parent")?; + .wrap_err("Not manifest parent")?; for entry in fs::read_dir(parent)? { let entry = entry?; let file_path = entry.path(); @@ -99,8 +99,8 @@ impl DependencyData { Ok(()) } - pub fn get_parse_licenses(&mut self) -> anyhow::Result<()> { - let license_metadata = self.license.clone().context("License not found")?; + pub fn get_parse_licenses(&mut self) -> Result<()> { + let license_metadata = self.license.clone().wrap_err("License not found")?; let expression = match Expression::parse(&license_metadata) { Ok(spdx) => spdx, @@ -134,7 +134,7 @@ impl DependencyData { pub fn get_data( metadata: Metadata, only_normal_dependencies: bool, -) -> anyhow::Result<(Vec, Option)> { +) -> Result<(Vec, Option)> { let mut dependencies = Vec::with_capacity(metadata.packages.len()); let mut my_crate = None; diff --git a/src/serialize.rs b/src/serialize.rs index 7323537..a27d5b9 100644 --- a/src/serialize.rs +++ b/src/serialize.rs @@ -5,6 +5,7 @@ use std::{fs::File, io::Write, path::Path}; +use color_eyre::eyre::Result; use serde::Serialize; use toml_edit::{ArrayOfTables, Document, Item, Table}; @@ -25,7 +26,7 @@ impl<'a> DependencySerialized<'a> { } } - pub fn to_toml(&self) -> anyhow::Result { + pub fn to_toml(&self) -> Result { // Serialize your struct to a TOML string let toml_str = toml::to_string_pretty(&self)?; @@ -48,7 +49,7 @@ impl<'a> DependencySerialized<'a> { Ok(toml_str) } - pub fn create_toml(&self, output_dir: &Path) -> anyhow::Result<()> { + pub fn create_toml(&self, output_dir: &Path) -> Result<()> { let mut file = File::create(output_dir.join(format!("{}.toml", self.file_name)))?; file.write_all(self.to_toml()?.as_bytes())?; Ok(()) @@ -71,7 +72,7 @@ impl<'a> SelfSerialized<'a> { } } - pub fn to_toml(&self) -> anyhow::Result { + pub fn to_toml(&self) -> Result { // Serialize your struct to a TOML string let toml_str = toml::to_string_pretty(&self)?; @@ -95,7 +96,7 @@ impl<'a> SelfSerialized<'a> { Ok(toml_str) } - pub fn create_toml(&self, output_dir: &Path) -> anyhow::Result<()> { + pub fn create_toml(&self, output_dir: &Path) -> Result<()> { let mut file = File::create(output_dir.join(format!("{}.toml", self.file_name)))?; file.write_all(self.to_toml()?.as_bytes())?; Ok(())