mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 21:52:37 +00:00
Add "do not sort" option
This commit is contained in:
parent
082c822684
commit
97815faee2
3 changed files with 30 additions and 9 deletions
19
src/app.rs
19
src/app.rs
|
@ -158,6 +158,7 @@ pub fn build() -> App<'static, 'static> {
|
|||
.overrides_with("extensionsort")
|
||||
.overrides_with("versionsort")
|
||||
.overrides_with("sort")
|
||||
.overrides_with("unsorted")
|
||||
.multiple(true)
|
||||
.help("Sort by time modified"),
|
||||
)
|
||||
|
@ -169,6 +170,7 @@ pub fn build() -> App<'static, 'static> {
|
|||
.overrides_with("extensionsort")
|
||||
.overrides_with("versionsort")
|
||||
.overrides_with("sort")
|
||||
.overrides_with("unsorted")
|
||||
.multiple(true)
|
||||
.help("Sort by size"),
|
||||
)
|
||||
|
@ -180,6 +182,7 @@ pub fn build() -> App<'static, 'static> {
|
|||
.overrides_with("timesort")
|
||||
.overrides_with("versionsort")
|
||||
.overrides_with("sort")
|
||||
.overrides_with("unsorted")
|
||||
.multiple(true)
|
||||
.help("Sort by file extension"),
|
||||
)
|
||||
|
@ -192,21 +195,35 @@ pub fn build() -> App<'static, 'static> {
|
|||
.overrides_with("sizesort")
|
||||
.overrides_with("extensionsort")
|
||||
.overrides_with("sort")
|
||||
.overrides_with("unsorted")
|
||||
.help("Natural sort of (version) numbers within text"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("sort")
|
||||
.long("sort")
|
||||
.multiple(true)
|
||||
.possible_values(&["size", "time", "version", "extension"])
|
||||
.possible_values(&["size", "time", "version", "extension", "none"])
|
||||
.takes_value(true)
|
||||
.value_name("WORD")
|
||||
.overrides_with("timesort")
|
||||
.overrides_with("sizesort")
|
||||
.overrides_with("extensionsort")
|
||||
.overrides_with("versionsort")
|
||||
.overrides_with("unsorted")
|
||||
.help("sort by WORD instead of name")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("unsorted")
|
||||
.short("U")
|
||||
.long("unsorted")
|
||||
.multiple(true)
|
||||
.overrides_with("timesort")
|
||||
.overrides_with("sizesort")
|
||||
.overrides_with("extensionsort")
|
||||
.overrides_with("sort")
|
||||
.overrides_with("versionsort")
|
||||
.help("Do not sort")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("reverse")
|
||||
.short("r")
|
||||
|
|
|
@ -37,6 +37,7 @@ impl Sorting {
|
|||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum SortColumn {
|
||||
None,
|
||||
Extension,
|
||||
Name,
|
||||
Time,
|
||||
|
@ -62,6 +63,8 @@ impl Configurable<Self> for SortColumn {
|
|||
Some(Self::Extension)
|
||||
} else if matches.is_present("versionsort") || sort == Some("version") {
|
||||
Some(Self::Version)
|
||||
} else if matches.is_present("unsorted") || sort == Some("none") {
|
||||
Some(Self::None)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
17
src/sort.rs
17
src/sort.rs
|
@ -16,14 +16,15 @@ pub fn assemble_sorters(flags: &Flags) -> Vec<(SortOrder, SortFn)> {
|
|||
}
|
||||
DirGrouping::None => {}
|
||||
};
|
||||
let other_sort = match flags.sorting.column {
|
||||
SortColumn::Name => by_name,
|
||||
SortColumn::Size => by_size,
|
||||
SortColumn::Time => by_date,
|
||||
SortColumn::Version => by_version,
|
||||
SortColumn::Extension => by_extension,
|
||||
};
|
||||
sorters.push((flags.sorting.order, other_sort));
|
||||
|
||||
match flags.sorting.column {
|
||||
SortColumn::Name => sorters.push((flags.sorting.order, by_name)),
|
||||
SortColumn::Size => sorters.push((flags.sorting.order, by_size)),
|
||||
SortColumn::Time => sorters.push((flags.sorting.order, by_date)),
|
||||
SortColumn::Version => sorters.push((flags.sorting.order, by_version)),
|
||||
SortColumn::Extension => sorters.push((flags.sorting.order, by_extension)),
|
||||
SortColumn::None => {}
|
||||
}
|
||||
sorters
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue