Skip to content

Commit

Permalink
More refactors, setup better clippy linting
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored and nickgerace committed Dec 9, 2024
1 parent 16fc296 commit 9e7313c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
5 changes: 5 additions & 0 deletions bin/gfold/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ serde_json = { workspace = true }
termcolor = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }

[lints.clippy]
all = "warn"
pedantic = "warn"
module_name_repetitions = "allow"
3 changes: 1 addition & 2 deletions bin/gfold/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ impl CliHarness {
let (include_email, include_submodules) = match config.display_mode {
DisplayMode::Classic => (false, false),
DisplayMode::Json => (true, true),
DisplayMode::Standard => (true, false),
DisplayMode::StandardAlphabetical => (true, false),
DisplayMode::Standard | DisplayMode::StandardAlphabetical => (true, false),
};
let repository_collection =
RepositoryCollector::run(&config.path, include_email, include_submodules)?;
Expand Down
26 changes: 11 additions & 15 deletions bin/gfold/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,14 @@ impl DisplayHarness {
all_reports.sort_by(|a, b| a.status.as_str().cmp(b.status.as_str()));
}

let color_harness = ColorHarness::new(&color_mode);
let color_harness = ColorHarness::new(color_mode);

for report in all_reports {
color_harness.write_bold(&report.name, false)?;

let parent = match report.parent {
Some(s) => s,
None => {
warn!("parent is empty for collector: {}", report.name);
continue;
}
let Some(parent) = report.parent else {
warn!("parent is empty for collector: {}", report.name);
continue;
};
let full_path = Path::new(&parent).join(&report.name);
let full_path_formatted = format!(
Expand All @@ -86,7 +83,7 @@ impl DisplayHarness {
color_harness.write_gray(&full_path_formatted, true)?;

print!(" ");
color_harness.write_status(&report.status, PAD)?;
color_harness.write_status(report.status, PAD)?;
println!(" ({})", report.branch);
if let Some(url) = &report.url {
println!(" {url}");
Expand Down Expand Up @@ -114,18 +111,17 @@ impl DisplayHarness {
/// Display [`RepositoryCollection`] to `stdout` in the classic format.
fn classic(reports: &RepositoryCollection, color_mode: ColorMode) -> io::Result<()> {
debug!("detected classic display mode");
let color_harness = ColorHarness::new(&color_mode);
let color_harness = ColorHarness::new(color_mode);

let length = reports.keys().len();
let mut first = true;
for (title, group) in reports {
// FIXME(nick): make group title matching less cumbersome.
if length > 1 {
match first {
true => {
first = false;
}
false => println!(),
if first {
first = false;
} else {
println!();
}
color_harness.write_bold(
match &title {
Expand Down Expand Up @@ -158,7 +154,7 @@ impl DisplayHarness {

for report in reports {
print!("{:<path_width$}", report.name, path_width = name_max + PAD);
color_harness.write_status(&report.status, status_max + PAD)?;
color_harness.write_status(report.status, status_max + PAD)?;
println!(
"{:<branch_width$}{}",
report.branch,
Expand Down
11 changes: 6 additions & 5 deletions bin/gfold/src/display/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ColorHarness {
}

impl ColorHarness {
pub fn new(color_mode: &ColorMode) -> Self {
pub fn new(color_mode: ColorMode) -> Self {
Self {
color_choice: match &color_mode {
ColorMode::Always => ColorChoice::Always,
Expand All @@ -25,7 +25,7 @@ impl ColorHarness {
}

/// Writes the [`Status`] of the Git repository to `stdout`.
pub fn write_status(&self, status: &Status, status_width: usize) -> io::Result<()> {
pub fn write_status(&self, status: Status, status_width: usize) -> io::Result<()> {
let mut stdout = StandardStream::stdout(self.color_choice);
stdout.set_color(ColorSpec::new().set_fg(Some(match status {
Status::Bare | Status::Unknown => Color::Red,
Expand Down Expand Up @@ -68,9 +68,10 @@ impl ColorHarness {
) -> io::Result<()> {
let mut stdout = StandardStream::stdout(self.color_choice);
stdout.set_color(color_spec)?;
match newline {
true => writeln!(&mut stdout, "{input}")?,
false => write!(&mut stdout, "{input}")?,
if newline {
writeln!(&mut stdout, "{input}")?;
} else {
write!(&mut stdout, "{input}")?;
}
stdout.reset()
}
Expand Down
4 changes: 2 additions & 2 deletions bin/gfold/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ mod display;
/// [`CliHarness::run()`].
fn main() -> anyhow::Result<()> {
if env::var("RUST_LOG").is_err() {
Builder::new().filter_level(LevelFilter::Off).init()
Builder::new().filter_level(LevelFilter::Off).init();
} else {
env_logger::init()
env_logger::init();
}
debug!("initialized logger");

Expand Down

0 comments on commit 9e7313c

Please sign in to comment.