diff --git a/CHANGELOG.md b/CHANGELOG.md index 969564520..40c2e0f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/lsd.md b/doc/lsd.md index 636913e75..2533df881 100644 --- a/doc/lsd.md +++ b/doc/lsd.md @@ -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 diff --git a/src/app.rs b/src/app.rs index a288eba52..04e26d650 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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= option #[arg(short, long)] - human_readable: bool, + pub human_readable: bool, /// Recurse into directories and present the result as a tree #[arg(long)] diff --git a/src/flags/size.rs b/src/flags/size.rs index 4a116cc50..d102b68ec 100644 --- a/src/flags/size.rs +++ b/src/flags/size.rs @@ -40,6 +40,9 @@ impl Configurable for SizeFlag { /// `SizeFlag` variant is returned in a [Some]. If neither of them is passed, this returns /// [None]. fn from_cli(cli: &Cli) -> Option { + if cli.human_readable { + return Some(Self::Default); + } if cli.classic { Some(Self::Bytes) } else { @@ -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"];