Jelajahi Sumber

fix: move options into flags

This fixes a clippy warning.
Erwin van Eijk 1 tahun lalu
induk
melakukan
0529538f14
2 mengubah file dengan 12 tambahan dan 12 penghapusan
  1. 10 10
      src/fs/filter.rs
  2. 2 2
      src/options/filter.rs

+ 10 - 10
src/fs/filter.rs

@@ -33,6 +33,14 @@ pub enum FileFilterFlags {
 
 
     /// Whether to explicitly show symlinks
     /// Whether to explicitly show symlinks
     ShowSymlinks,
     ShowSymlinks,
+    
+    /// Whether directories should be listed first, and other types of file
+    /// second. Some users prefer it like this.
+    ListDirsFirst,
+    
+    /// Whether directories should be listed as the last items, after other
+    /// types of file. Some users prefer it like this.
+    ListDirsLast,
 }
 }
 
 
 /// The **file filter** processes a list of files before displaying them to
 /// The **file filter** processes a list of files before displaying them to
@@ -51,14 +59,6 @@ pub enum FileFilterFlags {
 /// performing the comparison.
 /// performing the comparison.
 #[derive(PartialEq, Eq, Debug, Clone)]
 #[derive(PartialEq, Eq, Debug, Clone)]
 pub struct FileFilter {
 pub struct FileFilter {
-    /// Whether directories should be listed first, and other types of file
-    /// second. Some users prefer it like this.
-    pub list_dirs_first: bool,
-
-    /// Whether directories should be listed as the last items, after other
-    /// types of file. Some users prefer it like this.
-    pub list_dirs_last: bool,
-
     /// The metadata field to sort by.
     /// The metadata field to sort by.
     pub sort_field: SortField,
     pub sort_field: SortField,
 
 
@@ -143,7 +143,7 @@ impl FileFilter {
             files.reverse();
             files.reverse();
         }
         }
 
 
-        if self.list_dirs_first {
+        if self.flags.contains(&FileFilterFlags::ListDirsFirst) {
             // This relies on the fact that `sort_by` is *stable*: it will keep
             // This relies on the fact that `sort_by` is *stable*: it will keep
             // adjacent elements next to each other.
             // adjacent elements next to each other.
             files.sort_by(|a, b| {
             files.sort_by(|a, b| {
@@ -151,7 +151,7 @@ impl FileFilter {
                     .points_to_directory()
                     .points_to_directory()
                     .cmp(&a.as_ref().points_to_directory())
                     .cmp(&a.as_ref().points_to_directory())
             });
             });
-        } else if self.list_dirs_last {
+        } else if self.flags.contains(&FileFilterFlags::ListDirsLast) {
             files.sort_by(|a, b| {
             files.sort_by(|a, b| {
                 a.as_ref()
                 a.as_ref()
                     .points_to_directory()
                     .points_to_directory()

+ 2 - 2
src/options/filter.rs

@@ -26,6 +26,8 @@ impl FileFilter {
             (matches.has(&flags::ONLY_FILES)?, FFF::OnlyFiles),
             (matches.has(&flags::ONLY_FILES)?, FFF::OnlyFiles),
             (matches.has(&flags::NO_SYMLINKS)?, FFF::NoSymlinks),
             (matches.has(&flags::NO_SYMLINKS)?, FFF::NoSymlinks),
             (matches.has(&flags::SHOW_SYMLINKS)?, FFF::ShowSymlinks),
             (matches.has(&flags::SHOW_SYMLINKS)?, FFF::ShowSymlinks),
+            (matches.has(&flags::DIRS_LAST)?, FFF::ListDirsLast),
+            (matches.has(&flags::DIRS_FIRST)?, FFF::ListDirsFirst)
         ] {
         ] {
             if *has {
             if *has {
                 filter_flags.push(flag.clone());
                 filter_flags.push(flag.clone());
@@ -34,8 +36,6 @@ impl FileFilter {
 
 
         #[rustfmt::skip]
         #[rustfmt::skip]
         return Ok(Self {
         return Ok(Self {
-            list_dirs_first:  matches.has(&flags::DIRS_FIRST)?,
-            list_dirs_last:   matches.has(&flags::DIRS_LAST)?,
             no_symlinks:      filter_flags.contains(&FFF::NoSymlinks),
             no_symlinks:      filter_flags.contains(&FFF::NoSymlinks),
             show_symlinks:    filter_flags.contains(&FFF::ShowSymlinks),
             show_symlinks:    filter_flags.contains(&FFF::ShowSymlinks),
             flags:            filter_flags,
             flags:            filter_flags,