Skip to content
Closed
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
66 changes: 66 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cli-completions = ["cli"]

[dependencies]
assert-cmp = "0.3.0"
bon = "3.9.0"
clap = { version = "4.5.60", optional = true }
clap_complete = { version = "4.5.66", optional = true }
clap-utilities = { version = "0.3.0", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions src/app/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use crate::{
status_board::GLOBAL_STATUS_BOARD,
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
};
use bon::Builder;
use pipe_trait::Pipe;
use serde::Serialize;
use std::{io::stdout, iter::once, path::PathBuf};

/// The sub program of the main application.
#[derive(Builder)]
pub struct Sub<Size, SizeGetter, HardlinksHandler, Report>
where
Report: ParallelReporter<Size> + Sync,
Expand Down
18 changes: 10 additions & 8 deletions src/fs_tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{
size,
tree_builder::{Info, TreeBuilder},
};
use bon::Builder;
use pipe_trait::Pipe;
use std::{
fs::{read_dir, symlink_metadata},
Expand All @@ -27,16 +28,17 @@ use std::{
/// size::Bytes,
/// hardlink::HardlinkIgnorant,
/// };
/// let builder = FsTreeBuilder {
/// root: std::env::current_dir().unwrap(),
/// hardlinks_recorder: &HardlinkIgnorant,
/// size_getter: GetApparentSize,
/// reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
/// max_depth: 10,
/// };
/// let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
/// let builder = FsTreeBuilder::builder()
/// .root(std::env::current_dir().unwrap())
/// .hardlinks_recorder(&HardlinkIgnorant)
/// .size_getter(GetApparentSize)
/// .reporter(&reporter)
/// .max_depth(10)
/// .build();
/// let data_tree: DataTree<OsStringDisplay, Bytes> = builder.into();
/// ```
#[derive(Debug)]
#[derive(Debug, Builder)]
pub struct FsTreeBuilder<'a, Size, SizeGetter, HardlinksRecorder, Report>
where
Report: Reporter<Size> + Sync + ?Sized,
Expand Down
3 changes: 2 additions & 1 deletion src/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ pub mod info;
pub use info::Info;

use super::{data_tree::DataTree, size};
use bon::Builder;
use rayon::prelude::*;

/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
#[derive(Debug)]
#[derive(Debug, Builder)]
pub struct TreeBuilder<Path, Name, Size, GetInfo, JoinPath>
where
Path: Send + Sync,
Expand Down
17 changes: 9 additions & 8 deletions src/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use proportion_bar::{ProportionBar, ProportionBarBlock};
pub use tree::{TreeHorizontalSlice, TreeSkeletalComponent};

use super::{data_tree::DataTree, size};
use bon::Builder;
use std::fmt::Display;

/// Visualize a [`DataTree`].
Expand All @@ -32,17 +33,17 @@ use std::fmt::Display;
/// # use parallel_disk_usage::visualizer::{Visualizer, Direction, BarAlignment, ColumnWidthDistribution};
/// # fn _wrapper(create_data_tree: fn() -> DataTree<OsStringDisplay, Bytes>) {
/// let data_tree: DataTree<OsStringDisplay, Bytes> = create_data_tree();
/// let visualizer = Visualizer {
/// data_tree: &data_tree,
/// bytes_format: BytesFormat::MetricUnits,
/// direction: Direction::BottomUp,
/// bar_alignment: BarAlignment::Right,
/// column_width_distribution: ColumnWidthDistribution::total(100),
/// };
/// let visualizer = Visualizer::builder()
/// .data_tree(&data_tree)
/// .bytes_format(BytesFormat::MetricUnits)
/// .direction(Direction::BottomUp)
/// .bar_alignment(BarAlignment::Right)
/// .column_width_distribution(ColumnWidthDistribution::total(100))
/// .build();
/// println!("{visualizer}");
/// # }
/// ```
#[derive(Debug)]
#[derive(Debug, Builder)]
pub struct Visualizer<'a, Name, Size>
where
Name: Display,
Expand Down
22 changes: 11 additions & 11 deletions tests/_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,18 @@ where
}

let measure = |suffix: &str| {
FsTreeBuilder {
size_getter,
hardlinks_recorder: &HardlinkIgnorant,
reporter: &ErrorOnlyReporter::new(|error| {
FsTreeBuilder::builder()
.size_getter(size_getter)
.hardlinks_recorder(&HardlinkIgnorant)
.reporter(&ErrorOnlyReporter::new(|error| {
panic!("Unexpected call to report_error: {error:?}")
}),
root: root.join(suffix),
max_depth: 10,
}
.pipe(DataTree::<OsStringDisplay, Size>::from)
.into_par_sorted(|left, right| left.name().cmp(right.name()))
.into_reflection()
}))
.root(root.join(suffix))
.max_depth(10)
.build()
.pipe(DataTree::<OsStringDisplay, Size>::from)
.into_par_sorted(|left, right| left.name().cmp(right.name()))
.into_reflection()
};

let sub = |suffix: &str| root.join(suffix).pipe(OsStringDisplay::os_string_from);
Expand Down
29 changes: 15 additions & 14 deletions tests/cli_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,24 @@ fn fs_errors() {
dbg!(&status);
eprintln!("STDERR+STDOUT:\n{stderr}{stdout}\n");

let builder = FsTreeBuilder {
root: workspace.to_path_buf(),
size_getter: GetApparentSize,
hardlinks_recorder: &HardlinkIgnorant,
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
max_depth: 10,
};
let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
let builder = FsTreeBuilder::builder()
.root(workspace.to_path_buf())
.size_getter(GetApparentSize)
.hardlinks_recorder(&HardlinkIgnorant)
.reporter(&reporter)
.max_depth(10)
.build();
let mut data_tree: DataTree<OsStringDisplay, _> = builder.into();
data_tree.par_sort_by(|left, right| left.size().cmp(&right.size()).reverse());
*data_tree.name_mut() = OsStringDisplay::os_string_from(".");
let visualizer = Visualizer {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
};
let visualizer = Visualizer::builder()
.data_tree(&data_tree)
.bytes_format(BytesFormat::MetricUnits)
.direction(Direction::BottomUp)
.bar_alignment(BarAlignment::Left)
.column_width_distribution(ColumnWidthDistribution::total(100))
.build();
let expected_stdout = format!("{visualizer}");
eprintln!("EXPECTED STDOUT:\n{}\n", &expected_stdout);

Expand Down
30 changes: 16 additions & 14 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ fn json_output() {
.tree
.pipe(sanitize_tree_reflection);
dbg!(&actual);
let builder = FsTreeBuilder {
root: workspace.to_path_buf(),
size_getter: GetApparentSize,
hardlinks_recorder: &HardlinkIgnorant,
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
max_depth: 10,
};
let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
let builder = FsTreeBuilder::builder()
.root(workspace.to_path_buf())
.size_getter(GetApparentSize)
.hardlinks_recorder(&HardlinkIgnorant)
.reporter(&reporter)
.max_depth(10)
.build();
let expected = builder
.pipe(DataTree::<_, Bytes>::from)
.into_reflection()
Expand Down Expand Up @@ -135,13 +136,14 @@ fn json_input() {
let actual = actual.trim_end();
eprintln!("ACTUAL:\n{actual}\n");

let visualizer = Visualizer {
data_tree: &sample_tree(),
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
};
let tree = sample_tree();
let visualizer = Visualizer::builder()
.data_tree(&tree)
.bytes_format(BytesFormat::MetricUnits)
.direction(Direction::BottomUp)
.bar_alignment(BarAlignment::Left)
.column_width_distribution(ColumnWidthDistribution::total(100))
.build();
let expected = format!("{visualizer}");
let expected = expected.trim_end();
eprintln!("EXPECTED:\n{expected}\n");
Expand Down
20 changes: 10 additions & 10 deletions tests/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl SampleTree {
}

fn tree(&self, root: &'static str) -> DataTree<SampleName, SampleData> {
TreeBuilder {
path: root.to_string(),
name: root.to_string(),
get_info: |path| {
TreeBuilder::builder()
.path(root.to_string())
.name(root.to_string())
.get_info(|path| {
let path: Vec<_> = path
.split(SAMPLE_SEPARATOR)
.map(ToString::to_string)
Expand All @@ -56,12 +56,12 @@ impl SampleTree {
)),
None => panic!("Path does not exist"),
}
},
join_path: |prefix, name| format!("{prefix}{SAMPLE_SEPARATOR}{name}"),
max_depth: 10,
}
.pipe(DataTree::from)
.into_par_sorted(|left, right| left.name().as_str().cmp(right.name().as_str()))
})
.join_path(|prefix, name| format!("{prefix}{SAMPLE_SEPARATOR}{name}"))
.max_depth(10)
.build()
.pipe(DataTree::from)
.into_par_sorted(|left, right| left.name().as_str().cmp(right.name().as_str()))
}
}

Expand Down
Loading
Loading