Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

human readable flag (-h) enabled #906

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
configuration fields) to truncate user and group names if they exceed a certain number
of characters (disabled by default).

### Fixed

### Changed
- Human readable size flag `-h` re-enabled. [sdorr0](https://github.com/sdorr0)

## [v1.0.0] - 2023-08-25

### Added
Expand Down
2 changes: 1 addition & 1 deletion doc/lsd.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lsd is a ls command with a lot of pretty colours and some other stuff to enrich
: Prints help information

`-h`, `--human-readable`
: For ls compatibility purposes ONLY, currently set by default
: Use the `default` display size to show sizes as e.g., 1.7 KB, 3.0 GB, etc.

`--ignore-config`
: Ignore the configuration file
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub struct Cli {
#[arg(short = 'R', long, conflicts_with = "tree")]
pub recursive: bool,

/// For ls compatibility purposes ONLY, currently set by default
/// This will take precedence over any --size=<mode> option
#[arg(short, long)]
human_readable: bool,
pub human_readable: bool,

/// Recurse into directories and present the result as a tree
#[arg(long)]
Expand Down
17 changes: 17 additions & 0 deletions src/flags/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ impl Configurable<Self> for SizeFlag {
/// `SizeFlag` variant is returned in a [Some]. If neither of them is passed, this returns
/// [None].
fn from_cli(cli: &Cli) -> Option<Self> {
if cli.human_readable {
return Some(Self::Default);
}
if cli.classic {
Some(Self::Bytes)
} else {
Expand Down Expand Up @@ -97,6 +100,20 @@ mod test {
assert_eq!(Some(SizeFlag::Short), SizeFlag::from_cli(&cli));
}

#[test]
fn test_from_cli_human_readable() {
let argv = ["lsd", "--human-readable"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(Some(SizeFlag::Default), SizeFlag::from_cli(&cli));
}

#[test]
fn test_from_cli_minus_h() {
let argv = ["lsd", "-h"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(Some(SizeFlag::Default), SizeFlag::from_cli(&cli));
}

#[test]
fn test_from_cli_bytes() {
let argv = ["lsd", "--size", "bytes"];
Expand Down