Skip to content

Commit

Permalink
Clean up dependencies after splitting lib & CLI
Browse files Browse the repository at this point in the history
The library no longer depends on clap, fern, or tokio, except for tests. The result crate has been
removed entirely since I was only using it in one spot to save 3 or so lines of code.
  • Loading branch information
autarch committed Sep 2, 2024
1 parent 584d46b commit 8f8e6d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions precious.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmd = [
ok_exit_codes = 0
lint_failure_exit_codes = 101
expect_stderr = true
labels = ["default"]

[commands."clippy --fix"]
type = "tidy"
Expand All @@ -43,6 +44,7 @@ cmd = [
ok_exit_codes = 0
lint_failure_exit_codes = 101
expect_stderr = true
labels = ["default"]

[commands.rustfmt]
type = "both"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -112,3 +118,4 @@ lint_flags = "--check"
ok_exit_codes = 0
lint_failure_exit_codes = 1
ignore_stderr = "INFO taplo.+"
labels = ["default", "fast-tidy"]
2 changes: 1 addition & 1 deletion ubi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions ubi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@ 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
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
Expand All @@ -43,8 +39,10 @@ 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
18 changes: 12 additions & 6 deletions ubi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -235,7 +230,11 @@ impl<'a> Ubi<'a> {
platform: &'a Platform,
github_api_url_base: Option<String>,
) -> Result<Ubi<'a>> {
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)?;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8f8e6d1

Please sign in to comment.