Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add tracing and improve error messages #31

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 2 additions & 157 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dunce = "1"
schemars = { version = "0.8", features = ["url", "preserve_order", "derive"] }
cargo-packager-config = { path = "crates/config", version = "0.0.0" }
clap = { version = "4.4", features = ["derive"] }
log = "0.4"
dirs = "5.0"
semver = "1"
base64 = "0.21"
tracing = "0.1"
9 changes: 6 additions & 3 deletions crates/packager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ license = "Apache-2.0 OR MIT"

[features]
default = ["cli"]
cli = ["env_logger", "clap", "cargo-packager-config/clap"]
cli = ["clap", "cargo-packager-config/clap", "tracing", "tracing-subscriber"]
tracing = ["dep:tracing"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "doc_cfg"]
Expand All @@ -33,9 +34,11 @@ dirs.workspace = true
semver.workspace = true
base64.workspace = true
clap = { workspace = true, optional = true, features = ["env"] }
log = { workspace = true, features = ["kv_unstable", "kv_unstable_std"] }
tracing = { workspace = true, optional = true }
tracing-subscriber = { version = "0.3", optional = true, features = [
"env-filter",
] }
toml = "0.8"
env_logger = { version = "0.10", optional = true }
cargo_metadata = "0.18"
ureq = "2.7"
hex = "0.4"
Expand Down
24 changes: 15 additions & 9 deletions crates/packager/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::path::{Path, PathBuf};
use std::{
fmt::Debug,
path::{Path, PathBuf},
};

use crate::{config::Binary, Config};

Expand Down Expand Up @@ -28,7 +31,10 @@ fn find_nearset_pkg_name(path: &Path) -> crate::Result<Option<String>> {
res
}

pub fn parse_config_file<P: AsRef<Path>>(path: P) -> crate::Result<Vec<(Option<PathBuf>, Config)>> {
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))]
pub fn parse_config_file<P: AsRef<Path> + Debug>(
path: P,
) -> crate::Result<Vec<(Option<PathBuf>, Config)>> {
let path = path.as_ref().to_path_buf().canonicalize()?;
let content = std::fs::read_to_string(&path)?;
let mut configs = match path.extension().and_then(|e| e.to_str()) {
Expand Down Expand Up @@ -62,25 +68,25 @@ pub fn parse_config_file<P: AsRef<Path>>(path: P) -> crate::Result<Vec<(Option<P
Ok(configs)
}

pub fn find_config_files() -> Vec<PathBuf> {
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))]
pub fn find_config_files() -> crate::Result<Vec<PathBuf>> {
let opts = glob::MatchOptions {
case_sensitive: false,
..Default::default()
};

[
glob::glob_with("**/packager.toml", opts)
.unwrap()
Ok([
glob::glob_with("**/packager.toml", opts)?
.flatten()
.collect::<Vec<_>>(),
glob::glob_with("**/packager.json", opts)
.unwrap()
glob::glob_with("**/packager.json", opts)?
.flatten()
.collect::<Vec<_>>(),
]
.concat()
.concat())
}

#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))]
pub fn load_configs_from_cargo_workspace(
release: bool,
profile: Option<String>,
Expand Down
Loading
Loading