Add --group-directories-first as an alias for --group-dirs=first

`ls` from coreutils has the `--group-directories-first` flag as the only
directory grouping option. This patch improves compatibility so that
users switching to `lsd` can continue using `--group-directories-first`.
This commit is contained in:
networkException 2022-01-25 18:19:38 +01:00 committed by Abin Simon
parent 1a63ccced0
commit e9ff6ca3e6
4 changed files with 24 additions and 0 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] - ReleaseDate
# Added
- Add `--group-directories-first` as an alias for `--group-dirs=first` to improve compatibility with `coreutils/ls`
## [0.21.0] - 2022-01-16
### Added

View file

@ -104,6 +104,9 @@ lsd is a ls command with a lot of pretty colours and some other stuff to enrich
`--group-dirs <group-dirs>...`
: Sort the directories then the files [default: none] [possible values: none, first, last]
`--group-directories-first`
: Groups the directories at the top before the files. Same as `--group-dirs=first`. Same as `--group-dirs=first`
`--icon <icon>...`
: When to print the icons [default: auto] [possible values: always, auto, never]

View file

@ -224,6 +224,11 @@ pub fn build() -> App<'static, 'static> {
.number_of_values(1)
.help("Sort the directories then the files"),
)
.arg(
Arg::with_name("group-directories-first")
.long("group-directories-first")
.help("Groups the directories at the top before the files. Same as --group-dirs=first")
)
.arg(
Arg::with_name("blocks")
.long("blocks")

View file

@ -171,6 +171,10 @@ impl Configurable<Self> for DirGrouping {
return Some(Self::None);
}
if matches.is_present("group-directories-first") {
return Some(Self::First);
}
if matches.occurrences_of("group-dirs") > 0 {
if let Some(group_dirs) = matches.values_of("group-dirs")?.last() {
return Self::from_str(group_dirs);
@ -528,6 +532,16 @@ mod test_dir_grouping {
);
}
#[test]
fn test_from_arg_matches_group_directories_first() {
let argv = vec!["lsd", "--group-directories-first"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
assert_eq!(
Some(DirGrouping::First),
DirGrouping::from_arg_matches(&matches)
);
}
#[test]
fn test_from_config_empty() {
assert_eq!(None, DirGrouping::from_config(&Config::with_none()));