mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 11:36:16 +00:00
df: use for loop over filesystems to display rows
Replace a loop over `Row` objects with a loop over `Filesystem` objects when it comes time to display each row of the output table. This helps with code structure, since the `Filesystem` is the primary object of interest in the `df` program. This makes it easier for us to independently vary how the list of filesystems is produced and how the list of filesystems is displayed.
This commit is contained in:
parent
fa6af85b8e
commit
6371eb8298
1 changed files with 18 additions and 7 deletions
|
@ -282,18 +282,29 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
// Get Point for each input_path
|
||||
get_point_list(&mounts, &paths)
|
||||
};
|
||||
let data: Vec<Row> = op_mount_points
|
||||
|
||||
// Get the list of filesystems to display in the output table.
|
||||
let filesystems: Vec<Filesystem> = op_mount_points
|
||||
.into_iter()
|
||||
.filter_map(Filesystem::new)
|
||||
.filter(|fs| fs.usage.blocks != 0 || opt.show_all_fs || opt.show_listed_fs)
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
|
||||
println!("{}", Header::new(&opt));
|
||||
// The running total of filesystem sizes and usage.
|
||||
//
|
||||
// This accumulator is computed in case we need to display the
|
||||
// total counts in the last row of the table.
|
||||
let mut total = Row::new("total");
|
||||
for row in data {
|
||||
println!("{}", DisplayRow::new(&row, &opt));
|
||||
total += row;
|
||||
|
||||
println!("{}", Header::new(&opt));
|
||||
for filesystem in filesystems {
|
||||
// If the filesystem is not empty, or if the options require
|
||||
// showing all filesystems, then print the data as a row in
|
||||
// the output table.
|
||||
if opt.show_all_fs || opt.show_listed_fs || filesystem.usage.blocks > 0 {
|
||||
let row = Row::from(filesystem);
|
||||
println!("{}", DisplayRow::new(&row, &opt));
|
||||
total += row;
|
||||
}
|
||||
}
|
||||
if opt.show_total {
|
||||
println!("{}", DisplayRow::new(&total, &opt));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue