Skip to content

Commit e0b1ac8

Browse files
committed
Use argument based logging configuration
- Use argument based logging configuration rather than one provided from the environment - Drop "lib.rs" from previous refactor - Remove "thiserror" and rely on "anyhow" purely - Update dependencies Signed-off-by: Nick Gerace <nickagerace@gmail.com>
1 parent ed2b330 commit e0b1ac8

File tree

12 files changed

+384
-445
lines changed

12 files changed

+384
-445
lines changed

Cargo.lock

Lines changed: 32 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ strip = true
2222
[dependencies]
2323
anyhow = { version = "1.0", features = ["backtrace"] }
2424
clap = { version = "4.5", features = ["derive"] }
25+
clap-verbosity-flag = "3.0.2"
2526
env_logger = { version = "0.11", features = [ "humantime" ], default-features = false }
2627
git2 = { version = "0.20", default-features = false }
2728
log = "0.4"
@@ -30,7 +31,6 @@ remain = "0.2"
3031
serde = { version = "1.0", features = ["derive"] }
3132
serde_json = "1.0"
3233
termcolor = "1.4"
33-
thiserror = "2.0"
3434
toml = "0.8"
3535
user_dirs = "0.2"
3636

justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
_default:
22
@just --list
33

4+
# Build and run at the debug level in the parent directory
5+
run:
6+
cargo run -- -vvv ..
7+
48
# Scan for potential bloat
59
bloat:
610
cargo bloat --release

src/collector.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
//! This module contains the functionality for generating reports.
22
3-
use rayon::prelude::*;
43
use std::collections::BTreeMap;
54
use std::path::Path;
5+
6+
use anyhow::Result;
7+
use rayon::prelude::*;
68
use target::TargetCollector;
7-
use thiserror::Error;
89

9-
use crate::repository_view::{RepositoryView, RepositoryViewError, RepositoryViewResult};
10+
use crate::repository_view::RepositoryView;
1011

1112
mod target;
1213

13-
#[allow(missing_docs)]
14-
#[remain::sorted]
15-
#[derive(Error, Debug)]
16-
pub enum CollectorError {
17-
#[error(transparent)]
18-
FromRepositoryView(#[from] RepositoryViewError),
19-
#[error(transparent)]
20-
FromStdIo(#[from] std::io::Error),
21-
}
22-
23-
/// The result type used when multiple kinds of errors can be encountered during collection.
24-
pub type CollectorResult<T> = Result<T, CollectorError>;
25-
2614
/// This type represents a [`BTreeMap`] using an optional [`String`] for keys, which represents the
2715
/// parent directory for a group of reports ([`Vec<RepositoryView>`]). The values corresponding to those keys
2816
/// are the actual groups of reports.
@@ -31,7 +19,7 @@ pub type CollectorResult<T> = Result<T, CollectorError>;
3119
/// sorted keys.
3220
pub type RepositoryCollection = BTreeMap<Option<String>, Vec<RepositoryView>>;
3321

34-
type UnprocessedRepositoryView = RepositoryViewResult<RepositoryView>;
22+
type UnprocessedRepositoryView = Result<RepositoryView>;
3523

3624
/// A unit struct that provides [`Self::run()`], which is used to generated [`RepositoryCollection`].
3725
#[derive(Debug)]
@@ -43,24 +31,18 @@ impl RepositoryCollector {
4331
path: &Path,
4432
include_email: bool,
4533
include_submodules: bool,
46-
) -> CollectorResult<RepositoryCollection> {
34+
) -> Result<RepositoryCollection> {
4735
let unprocessed = TargetCollector::run(path.to_path_buf())?
4836
.par_iter()
4937
.map(|path| RepositoryView::new(path, include_email, include_submodules))
5038
.collect::<Vec<UnprocessedRepositoryView>>();
5139

5240
let mut processed = RepositoryCollection::new();
5341
for maybe_view in unprocessed {
54-
match maybe_view {
55-
Ok(view) => {
56-
if let Some(mut views) =
57-
processed.insert(view.parent.clone(), vec![view.clone()])
58-
{
59-
views.push(view.clone());
60-
processed.insert(view.parent, views);
61-
}
62-
}
63-
Err(e) => return Err(e.into()),
42+
let view = maybe_view?;
43+
if let Some(mut views) = processed.insert(view.parent.clone(), vec![view.clone()]) {
44+
views.push(view.clone());
45+
processed.insert(view.parent, views);
6446
}
6547
}
6648
Ok(processed)

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{env, fs};
99
/// This struct is the actual config type consumed through the codebase. It is boostrapped via its
1010
/// public methods and uses [`EntryConfig`], a private struct, under the hood in order to
1111
/// deserialize empty, non-existent, partial, and complete config files.
12-
#[derive(Serialize)]
12+
#[derive(Debug, Serialize)]
1313
pub struct Config {
1414
/// The paths that `gfold` will traverse and collect results from.
1515
pub paths: Vec<PathBuf>,
@@ -131,7 +131,7 @@ struct EntryConfig {
131131
/// In summary, while this setting is primarily for cosmetics, it may also affect runtime
132132
/// performance based on what needs to be displayed.
133133
#[remain::sorted]
134-
#[derive(Serialize, Deserialize, Clone, Copy, ValueEnum)]
134+
#[derive(Debug, Serialize, Deserialize, Clone, Copy, ValueEnum)]
135135
pub enum DisplayMode {
136136
/// Informs the caller to display results in the classic format.
137137
Classic,
@@ -147,7 +147,7 @@ pub enum DisplayMode {
147147

148148
/// Set the color mode of results printed to `stdout`.
149149
#[remain::sorted]
150-
#[derive(Serialize, Deserialize, Clone, Copy, ValueEnum)]
150+
#[derive(Debug, Serialize, Deserialize, Clone, Copy, ValueEnum)]
151151
pub enum ColorMode {
152152
/// Attempt to display colors as intended (default behavior).
153153
Always,

src/display.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
//! This module contains the functionality for displaying reports to `stdout`.
22
3+
use std::io;
4+
use std::path::Path;
5+
6+
use anyhow::{anyhow, Result};
37
use color::ColorHarness;
4-
use gfold::RepositoryCollection;
58
use log::debug;
69
use log::warn;
7-
use std::io;
8-
use std::path::{Path, PathBuf};
9-
use thiserror::Error;
1010

11+
use crate::collector::RepositoryCollection;
1112
use crate::config::{ColorMode, DisplayMode};
1213

13-
mod color;
14+
// TODO(nick): make this module private.
15+
pub mod color;
1416

1517
const PAD: usize = 2;
1618
const NONE: &str = "none";
1719

18-
#[remain::sorted]
19-
#[derive(Error, Debug)]
20-
pub enum DisplayError {
21-
#[error("could not convert path (Path) to &str: {0}")]
22-
PathToStrConversionFailure(PathBuf),
23-
}
24-
2520
/// This struct is used for displaying the contents of a [`RepositoryCollection`] to `stdout`.
21+
#[derive(Debug)]
2622
pub struct DisplayHarness {
2723
display_mode: DisplayMode,
2824
color_mode: ColorMode,
@@ -37,7 +33,7 @@ impl DisplayHarness {
3733
}
3834

3935
/// This function chooses the display execution function based on the [`DisplayMode`] provided.
40-
pub fn run(&self, reports: &RepositoryCollection) -> anyhow::Result<()> {
36+
pub fn run(&self, reports: &RepositoryCollection) -> Result<()> {
4137
match self.display_mode {
4238
DisplayMode::Standard => Self::standard(reports, self.color_mode, false)?,
4339
DisplayMode::StandardAlphabetical => Self::standard(reports, self.color_mode, true)?,
@@ -52,7 +48,7 @@ impl DisplayHarness {
5248
reports: &RepositoryCollection,
5349
color_mode: ColorMode,
5450
alphabetical_sort_only: bool,
55-
) -> anyhow::Result<()> {
51+
) -> Result<()> {
5652
debug!("detected standard display mode");
5753
let mut all_reports = Vec::new();
5854
for grouped_report in reports {
@@ -76,9 +72,9 @@ impl DisplayHarness {
7672
let full_path = Path::new(&parent).join(&report.name);
7773
let full_path_formatted = format!(
7874
" ~ {}",
79-
full_path
80-
.to_str()
81-
.ok_or_else(|| DisplayError::PathToStrConversionFailure(full_path.clone()))?
75+
full_path.to_str().ok_or(anyhow!(
76+
"could not convert path (Path) to &str: {full_path:?}"
77+
))?
8278
);
8379
color_harness.write_gray(&full_path_formatted, true)?;
8480

src/display/color.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
//! This module provides a harness for non-trivial displays of information to `stdout`.
22
3-
use gfold::Status;
43
use std::io;
54
use std::io::Write;
65
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
76

8-
use crate::config::ColorMode;
7+
use crate::{config::ColorMode, status::Status};
98

109
/// This harness provides methods to write to `stdout`. It maps the internal [`ColorMode`] type to
1110
/// our dependency's [`ColorChoice`] type due to discrepancies in behavior and naming.
11+
#[derive(Debug)]
1212
pub struct ColorHarness {
1313
color_choice: ColorChoice,
1414
}
1515

1616
impl ColorHarness {
17+
/// Creates a new color harness.
1718
pub fn new(color_mode: ColorMode) -> Self {
1819
Self {
1920
color_choice: match &color_mode {

0 commit comments

Comments
 (0)