Skip to content

Commit 1005565

Browse files
committed
feat(api)!: add hook to Sub
1 parent a732d87 commit 1005565

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
args::{Args, Quantity, Threads},
77
bytes_format::BytesFormat,
88
get_size::{GetApparentSize, GetSize},
9+
hook,
910
json_data::{JsonData, UnitAndTree},
1011
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
1112
runtime_error::RuntimeError,
@@ -201,6 +202,7 @@ impl App {
201202
direction: Direction::from_top_down(top_down),
202203
bar_alignment: BarAlignment::from_align_right(align_right),
203204
size_getter: <$size_getter as GetSizeUtils>::INSTANCE,
205+
hook: hook::DoNothing, // TODO: change this
204206
reporter: <$size_getter as CreateReporter<$progress>>::create_reporter(report_error),
205207
bytes_format: <$size_getter as GetSizeUtils>::formatter(bytes_format),
206208
files,

src/app/sub.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ use serde::Serialize;
1616
use std::{io::stdout, iter::once, num::NonZeroU64, path::PathBuf};
1717

1818
/// The sub program of the main application.
19-
pub struct Sub<Size, SizeGetter, Report>
19+
pub struct Sub<Size, SizeGetter, Hook, Report>
2020
where
2121
Report: ParallelReporter<Size> + Sync,
2222
Size: size::Size + Into<u64> + Serialize + Send + Sync,
2323
SizeGetter: GetSize<Size = Size> + Copy + Sync,
24+
Hook: hook::Hook<Size> + Copy + Sync,
2425
DataTreeReflection<String, Size>: Into<UnitAndTree>,
2526
{
2627
/// List of files and/or directories.
@@ -39,6 +40,8 @@ where
3940
pub max_depth: NonZeroU64,
4041
/// [Get the size](GetSize) of files/directories.
4142
pub size_getter: SizeGetter,
43+
/// Hook to run after [`Self::size_getter`].
44+
pub hook: Hook,
4245
/// Reports measurement progress.
4346
pub reporter: Report,
4447
/// Minimal size proportion required to appear.
@@ -47,11 +50,12 @@ where
4750
pub no_sort: bool,
4851
}
4952

50-
impl<Size, SizeGetter, Report> Sub<Size, SizeGetter, Report>
53+
impl<Size, SizeGetter, Hook, Report> Sub<Size, SizeGetter, Hook, Report>
5154
where
5255
Size: size::Size + Into<u64> + Serialize + Send + Sync,
5356
Report: ParallelReporter<Size> + Sync,
5457
SizeGetter: GetSize<Size = Size> + Copy + Sync,
58+
Hook: hook::Hook<Size> + Copy + Sync,
5559
DataTreeReflection<String, Size>: Into<UnitAndTree>,
5660
{
5761
/// Run the sub program.
@@ -65,6 +69,7 @@ where
6569
column_width_distribution,
6670
max_depth,
6771
size_getter,
72+
hook,
6873
reporter,
6974
min_ratio,
7075
no_sort,
@@ -79,7 +84,7 @@ where
7984
reporter: &reporter,
8085
root,
8186
size_getter,
82-
hook: hook::DoNothing, // TODO: change this
87+
hook,
8388
max_depth,
8489
}
8590
.into()
@@ -90,6 +95,7 @@ where
9095
} else {
9196
return Sub {
9297
files: vec![".".into()],
98+
hook,
9399
reporter,
94100
..self
95101
}

0 commit comments

Comments
 (0)