Repository: eza-community/eza (language: rust)

Issue:
feat:  Listing files only
Like -D, add option to show files only. Let me know if its already there.


Discussion / hints:
Could you expand on what `-D` should do? Currently the `-D` flag is taken.
> Could you expand on what `-D` should do? Currently the `-D` flag is taken.

-D Lists folders/dirs. Like that maybe a flag like --files should display only files.

Fix patch:
diff --git a/README.md b/README.md
index 5a84668e8..cf2318d12 100644
--- a/README.md
+++ b/README.md
@@ -286,6 +286,7 @@ eza’s options are almost, but not quite, entirely unlike `ls`’s.
 - **-s**, **--sort=(field)**: which field to sort by
 - **--group-directories-first**: list directories before other files
 - **-D**, **--only-dirs**: list only directories
+- **-f**, **--only-files**: list only files
 - **--git-ignore**: ignore files mentioned in `.gitignore`
 - **-I**, **--ignore-glob=(globs)**: glob patterns (pipe-separated) of files to ignore
 
diff --git a/completions/fish/eza.fish b/completions/fish/eza.fish
index d4e7ad9a6..cc0b37acd 100644
--- a/completions/fish/eza.fish
+++ b/completions/fish/eza.fish
@@ -56,6 +56,7 @@ complete -c eza -s s -l sort -d "Which field to sort by" -x -a "
 
 complete -c eza -s I -l ignore-glob -d "Ignore files that match these glob patterns" -r
 complete -c eza -s D -l only-dirs -d "List only directories"
+complete -c eza -s f -l only-files -d "List only files"
 
 # Long view options
 complete -c eza -s b -l binary -d "List file sizes with binary prefixes"
diff --git a/completions/zsh/_eza b/completions/zsh/_eza
index 1fca93d89..f2f6981de 100644
--- a/completions/zsh/_eza
+++ b/completions/zsh/_eza
@@ -29,6 +29,7 @@ __eza() {
         {-a,--all}"[Show hidden and 'dot' files. Use this twice to also show the '.' and '..' directories]" \
         {-d,--list-dirs}"[List directories like regular files]" \
         {-D,--only-dirs}"[List only directories]" \
+        {-f,--only-files}"[List only files]" \
         {-L,--level}"+[Limit the depth of recursion]" \
         {-w,--width}"+[Limits column output of grid, 0 implies auto-width]" \
         {-r,--reverse}"[Reverse the sort order]" \
diff --git a/man/eza.1.md b/man/eza.1.md
index 5c539c155..a0bd895c8 100644
--- a/man/eza.1.md
+++ b/man/eza.1.md
@@ -119,6 +119,9 @@ Sort fields starting with a capital letter will sort uppercase before lowercase:
 `-D`, `--only-dirs`
 : List only directories, not files.
 
+`-f`, `--only-files`
+: List only files, not directories.
+
 
 LONG VIEW OPTIONS
 =================
diff --git a/src/fs/filter.rs b/src/fs/filter.rs
index 29492f42c..1071d621f 100644
--- a/src/fs/filter.rs
+++ b/src/fs/filter.rs
@@ -9,6 +9,23 @@ use crate::fs::DotFilter;
 use crate::fs::File;
 
 
+
+/// Flags used to manage the **file filter** process
+#[derive(PartialEq, Eq, Debug, Clone)]
+pub enum FileFilterFlags {
+    /// Whether to reverse the sorting order. This would sort the largest
+    /// files first, or files starting with Z, or the most-recently-changed
+    /// ones, depending on the sort field.
+    Reverse,
+
+    /// Whether to only show directories.
+    OnlyDirs,
+
+    /// Whether to only show files.
+    OnlyFiles
+}
+
+
 /// The **file filter** processes a list of files before displaying them to
 /// the user, by removing files they don’t want to see, and putting the list
 /// in the desired order.
@@ -33,13 +50,8 @@ pub struct FileFilter {
     /// The metadata field to sort by.
     pub sort_field: SortField,
 
-    /// Whether to reverse the sorting order. This would sort the largest
-    /// files first, or files starting with Z, or the most-recently-changed
-    /// ones, depending on the sort field.
-    pub reverse: bool,
-
-    /// Whether to only show directories.
-    pub only_dirs: bool,
+    // Flags that the file filtering process follow
+    pub flags: Vec<FileFilterFlags>,
 
     /// Which invisible “dot” files to include when listing a directory.
     ///
@@ -66,11 +78,22 @@ impl FileFilter {
     /// Remove every file in the given vector that does *not* pass the
     /// filter predicate for files found inside a directory.
     pub fn filter_child_files(&self, files: &mut Vec<File<'_>>) {
+        use FileFilterFlags::{OnlyDirs, OnlyFiles};
+        
         files.retain(|f| ! self.ignore_patterns.is_ignored(&f.name));
 
-        if self.only_dirs {
-            files.retain(File::is_directory);
+        match (self.flags.contains(&OnlyDirs), self.flags.contains(&OnlyFiles)) {
+            (true, false) => {
+                // On pass -'-only-dirs' flag only
+                files.retain(File::is_directory);
+            }
+            (false, true) => {
+                // On pass -'-only-files' flag only
+                files.retain(File::is_file);
+            }
+            _ => {}
         }
+       
     }
 
     /// Remove every file in the given vector that does *not* pass the
@@ -96,7 +119,7 @@ impl FileFilter {
             self.sort_field.compare_files(a.as_ref(), b.as_ref())
         });
 
-        if self.reverse {
+        if self.flags.contains(&FileFilterFlags::Reverse) {
             files.reverse();
         }
 
diff --git a/src/options/filter.rs b/src/options/filter.rs
index 9828767b8..44444d418 100644
--- a/src/options/filter.rs
+++ b/src/options/filter.rs
@@ -1,7 +1,7 @@
 //! Parsing the options for `FileFilter`.
 
 use crate::fs::DotFilter;
-use crate::fs::filter::{FileFilter, SortField, SortCase, IgnorePatterns, GitIgnore};
+use crate::fs::filter::{FileFilter,FileFilterFlags, SortField, SortCase, IgnorePatterns, GitIgnore};
 
 use crate::options::{flags, OptionsError};
 use crate::options::parser::MatchedFlags;
@@ -11,10 +11,22 @@ impl FileFilter {
 
     /// Determines which of all the file filter options to use.
     pub fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
+        use FileFilterFlags as FFF;
+        let mut filter_flags:Vec<FileFilterFlags> = vec![];
+            
+        for (has,flag) in &[
+            (matches.has(&flags::REVERSE)?, FFF::Reverse),
+            (matches.has(&flags::ONLY_DIRS)?, FFF::OnlyDirs),
+            (matches.has(&flags::ONLY_FILES)?, FFF::OnlyFiles),
+        ] {
+            if *has { 
+                filter_flags.push(flag.clone());
+            }
+        }
+
         Ok(Self {
             list_dirs_first:  matches.has(&flags::DIRS_FIRST)?,
-            reverse:          matches.has(&flags::REVERSE)?,
-            only_dirs:        matches.has(&flags::ONLY_DIRS)?,
+            flags: filter_flags,
             sort_field:       SortField::deduce(matches)?,
             dot_filter:       DotFilter::deduce(matches)?,
             ignore_patterns:  IgnorePatterns::deduce(matches)?,
diff --git a/src/options/flags.rs b/src/options/flags.rs
index 689d30212..eef974936 100644
--- a/src/options/flags.rs
+++ b/src/options/flags.rs
@@ -34,6 +34,7 @@ pub static IGNORE_GLOB: Arg = Arg { short: Some(b'I'), long: "ignore-glob", take
 pub static GIT_IGNORE:  Arg = Arg { short: None, long: "git-ignore",           takes_value: TakesValue::Forbidden };
 pub static DIRS_FIRST:  Arg = Arg { short: None, long: "group-directories-first",  takes_value: TakesValue::Forbidden };
 pub static ONLY_DIRS:   Arg = Arg { short: Some(b'D'), long: "only-dirs", takes_value: TakesValue::Forbidden };
+pub static ONLY_FILES:   Arg = Arg { short: Some(b'f'), long: "only-files", takes_value: TakesValue::Forbidden };
 const SORTS: Values = &[ "name", "Name", "size", "extension",
                          "Extension", "modified", "changed", "accessed",
                          "created", "inode", "type", "none" ];
@@ -83,7 +84,7 @@ pub static ALL_ARGS: Args = Args(&[
     &COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &WIDTH,
 
     &ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
-    &IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS,
+    &IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES,
 
     &BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,
     &BLOCKSIZE, &TIME, &ACCESSED, &CREATED, &TIME_STYLE, &HYPERLINK, &MOUNTS,
diff --git a/src/options/help.rs b/src/options/help.rs
index f8c79afae..05897e091 100644
--- a/src/options/help.rs
+++ b/src/options/help.rs
@@ -35,6 +35,7 @@ FILTERING AND SORTING OPTIONS
   -s, --sort SORT_FIELD      which field to sort by
   --group-directories-first  list directories before other files
   -D, --only-dirs            list only directories
+  -f, --only-files           list only files
   -I, --ignore-glob GLOBS    glob patterns (pipe-separated) of files to ignore";
 
 static GIT_FILTER_HELP: &str = "  \


Test patch:
diff --git a/tests/cmd/only_file_unix.stderr b/tests/cmd/only_file_unix.stderr
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/cmd/only_file_unix.stdout b/tests/cmd/only_file_unix.stdout
new file mode 100644
index 000000000..eb2fe543f
--- /dev/null
+++ b/tests/cmd/only_file_unix.stdout
@@ -0,0 +1,19 @@
+a
+b
+c
+d
+e
+f
+g
+h
+i
+image.jpg.img.c.rs.log.png
+index.svg
+j
+k
+l
+m
+n
+o
+p
+q
diff --git a/tests/cmd/only_file_unix.toml b/tests/cmd/only_file_unix.toml
new file mode 100644
index 000000000..2c492f233
--- /dev/null
+++ b/tests/cmd/only_file_unix.toml
@@ -0,0 +1,2 @@
+bin.name = "eza"
+args = "tests/itest --only-files"