diff --git a/Cargo.lock b/Cargo.lock index ca8bbe9..6352183 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1371,12 +1371,6 @@ dependencies = [ "windows-registry", ] -[[package]] -name = "result" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" - [[package]] name = "ring" version = "0.17.8" @@ -1897,7 +1891,6 @@ dependencies = [ "anyhow", "binstall-tar", "bzip2", - "clap", "document-features", "fern", "flate2", @@ -1908,7 +1901,6 @@ dependencies = [ "platforms", "regex", "reqwest", - "result", "serde", "strum", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 840bb48..3a584cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ mockito = "1.5.0" platforms = "=3.2.0" regex = "1.10.6" reqwest = { version = "0.12.7", default-features = false, features = ["gzip", "json"] } -result = "1.0.0" serde = { version = "1.0.209", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] } tempfile = "3.12.0" diff --git a/precious.toml b/precious.toml index 51bc0ce..18022dd 100644 --- a/precious.toml +++ b/precious.toml @@ -21,6 +21,7 @@ cmd = [ ok_exit_codes = 0 lint_failure_exit_codes = 101 expect_stderr = true +labels = ["default"] [commands."clippy --fix"] type = "tidy" @@ -43,6 +44,7 @@ cmd = [ ok_exit_codes = 0 lint_failure_exit_codes = 101 expect_stderr = true +labels = ["default"] [commands.rustfmt] type = "both" @@ -51,6 +53,7 @@ cmd = ["rustfmt", "--edition", "2021"] lint_flags = "--check" ok_exit_codes = [0] lint_failure_exit_codes = [1] +labels = ["default", "fast-tidy"] [commands.omegasort-gitignore] type = "both" @@ -61,6 +64,7 @@ tidy_flags = "--in-place" ok_exit_codes = 0 lint_failure_exit_codes = 1 expect_stderr = true +labels = ["default", "fast-tidy"] [commands.prettier] type = "both" @@ -78,6 +82,7 @@ tidy_flags = "--write" ok_exit_codes = 0 lint_failure_exit_codes = 1 ignore_stderr = "Code style issues" +labels = ["default", "fast-tidy"] [commands.shellcheck] type = "lint" @@ -94,6 +99,7 @@ lint_flags = "--diff" tidy_flags = "--write" ok_exit_codes = 0 lint_failure_exit_codes = 1 +labels = ["default", "fast-tidy"] [commands.typos] type = "lint" @@ -112,3 +118,4 @@ lint_flags = "--check" ok_exit_codes = 0 lint_failure_exit_codes = 1 ignore_stderr = "INFO taplo.+" +labels = ["default", "fast-tidy"] diff --git a/ubi-cli/Cargo.toml b/ubi-cli/Cargo.toml index 4b8e5c1..ffd5c04 100644 --- a/ubi-cli/Cargo.toml +++ b/ubi-cli/Cargo.toml @@ -15,7 +15,7 @@ log.workspace = true tempfile.workspace = true thiserror.workspace = true tokio.workspace = true -ubi = { version = "0.2.0", path = "../ubi" } +ubi = { version = "0.2.0", path = "../ubi", features = ["default", "logging"] } [[bin]] name = "ubi" diff --git a/ubi/Cargo.toml b/ubi/Cargo.toml index 8ffbe6c..858144b 100644 --- a/ubi/Cargo.toml +++ b/ubi/Cargo.toml @@ -12,9 +12,8 @@ edition.workspace = true anyhow.workspace = true binstall-tar.workspace = true bzip2.workspace = true -clap.workspace = true document-features.workspace = true -fern.workspace = true +fern = { workspace = true, optional = true } flate2.workspace = true itertools.workspace = true lazy-regex.workspace = true @@ -22,13 +21,10 @@ log.workspace = true platforms.workspace = true regex.workspace = true reqwest.workspace = true -result.workspace = true serde.workspace = true strum.workspace = true tempfile.workspace = true -test-case.workspace = true thiserror.workspace = true -tokio.workspace = true url.workspace = true xz.workspace = true zip.workspace = true @@ -43,9 +39,13 @@ rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"] native-tls = ["reqwest/native-tls"] ## enables the `native-tls-vendored` feature for the `reqwest` crate. native-tls-vendored = ["reqwest/native-tls-vendored"] +logging = ["dep:fern"] [dev-dependencies] +fern.workspace = true mockito.workspace = true +test-case.workspace = true +tokio.workspace = true # workaround for https://github.com/cross-rs/cross/issues/1345 [package.metadata.cross.target.x86_64-unknown-netbsd] diff --git a/ubi/src/lib.rs b/ubi/src/lib.rs index fac2649..dcd58e5 100644 --- a/ubi/src/lib.rs +++ b/ubi/src/lib.rs @@ -40,17 +40,12 @@ use crate::{ release::Download, }; use anyhow::{anyhow, Result}; -use fern::{ - colors::{Color, ColoredLevelConfig}, - Dispatch, -}; use log::debug; use platforms::{Platform, PlatformReq, OS}; use reqwest::{ header::{HeaderMap, HeaderValue, ACCEPT, AUTHORIZATION, USER_AGENT}, Client, StatusCode, }; -use result::OptionResultExt; use std::{ env, fs::{create_dir_all, File}, @@ -235,7 +230,11 @@ impl<'a> Ubi<'a> { platform: &'a Platform, github_api_url_base: Option, ) -> Result> { - let url = url.map(Url::parse).invert()?; + let url = if let Some(u) = url { + Some(Url::parse(u)?) + } else { + None + }; let project_name = Self::parse_project_name(project, url.as_ref())?; let exe = Self::exe_name(exe, &project_name, platform); let install_path = Self::install_path(install_dir, &exe)?; @@ -408,12 +407,19 @@ impl<'a> Ubi<'a> { } } +#[cfg(any(test, feature = "logging"))] +use fern::{ + colors::{Color, ColoredLevelConfig}, + Dispatch, +}; + /// This function initializes logging for the application. It's public for the sake of the `ubi` /// binary, but it lives in the library crate so that test code can also enable logging. /// /// # Errors /// /// This can return a `log::SetLoggerError` error. +#[cfg(any(test, feature = "logging"))] pub fn init_logger(level: log::LevelFilter) -> Result<(), log::SetLoggerError> { let line_colors = ColoredLevelConfig::new() .error(Color::Red)