Skip to content

Add --show-size flag to ouch list (#1005) - #1052

Open
ChrisJr404 wants to merge 2 commits into
ouch-org:mainfrom
ChrisJr404:feat/list-show-size
Open

Add --show-size flag to ouch list (#1005)#1052
ChrisJr404 wants to merge 2 commits into
ouch-org:mainfrom
ChrisJr404:feat/list-show-size

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds the --show-size flag to ouch list that was asked for in #1005, so you can see how big each entry is without extracting anything.

The sizes come straight from the archive metadata (tar/zip/7z/rar all report the uncompressed size per entry), so the plain ouch list output is byte-for-byte the same as before and you only get the extra column when you pass the flag. Files show a right-aligned size using the same BytesFmt the rest of ouch uses; directories get a blank, aligned column so things line up. It works in --tree mode too, with the size column sitting to the left of the branches.

$ ouch list proj.tar.gz --show-size
Archive: "proj.tar.gz"
            proj/
 12.00   B  proj/README.md
            proj/src/
  2.00   B  proj/src/tiny.txt
  3.00 kiB  proj/src/big.bin

Added an integration test covering both the flag and the unchanged default output.

Closes ouch-org#1005. The size comes from the archive metadata, so the default
listing stays untouched and only pays for reading sizes when the flag is
passed. Directories get a blank, aligned column and the flag also works
in --tree mode.

@marcospb19 marcospb19 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great code and great PR, thanks.

Cause I merged older PRs before, now you have conflicts, just 1 nitpick the rest is perfect.

Comment thread src/list.rs Outdated
Comment on lines +86 to +94
match (file_type, size) {
(ListFileType::File | ListFileType::Symlink { .. } | ListFileType::Hardlink { .. }, Some(size)) => {
let _ = write!(out, "{} ", BytesFmt(size));
}
_ => {
// `BytesFmt` renders as 10 columns, keep the padding in sync with it.
let _ = write!(out, "{:>10} ", "");
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick from me:

Suggested change
match (file_type, size) {
(ListFileType::File | ListFileType::Symlink { .. } | ListFileType::Hardlink { .. }, Some(size)) => {
let _ = write!(out, "{} ", BytesFmt(size));
}
_ => {
// `BytesFmt` renders as 10 columns, keep the padding in sync with it.
let _ = write!(out, "{:>10} ", "");
}
}
if let Some(size) = size
&& !matches!(file_type, ListFileType::Directory { .. })
{
let _ = write!(out, "{} ", BytesFmt(size));
} else {
// `BytesFmt` renders as 10 columns, keep the padding in sync with it.
let _ = write!(out, "{:>10} ", "");
}

# Conflicts:
#	src/cli/args.rs
#	src/commands/mod.rs
#	src/list.rs
#	tests/integration.rs
@ChrisJr404

Copy link
Copy Markdown
Author

Thanks! Applied your nitpick (the if let Some(size) = size && !matches!(file_type, ListFileType::Directory) form; dropped the { .. } since Directory is a unit variant, which clippy also prefers).

I also merged main to resolve the conflicts with the recently-merged --depth work. --show-size and --depth now compose: the size column is rendered inside the depth-limited traversal in both flat and tree views. Build, fmt, clippy, and both the list_show_size and list_depth integration tests pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants