diff options
author | Ben S <ogham@bsago.me> | 2015-02-26 14:05:26 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-02-26 14:05:26 +0000 |
commit | ff1f6d0087f6475474c77031ded85be9e35cebfa (patch) | |
tree | a352b1ffae3e0ec2898ac5f2e539e35001a5eddd /src/options.rs | |
parent | 982352009fffa5af3a469108772c63d12754bc44 (diff) |
Add --group-directories-first option
Closes #27.
Diffstat (limited to 'src/options.rs')
-rw-r--r-- | src/options.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/options.rs b/src/options.rs index 6a6c068..40a7b4b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -28,6 +28,7 @@ pub struct Options { #[derive(PartialEq, Debug, Copy)] pub struct FileFilter { + list_dirs_first: bool, reverse: bool, show_invisibles: bool, sort_field: SortField, @@ -51,6 +52,7 @@ impl Options { opts.optflag("B", "bytes", "list file sizes in bytes, without prefixes"); opts.optflag("d", "list-dirs", "list directories as regular files"); opts.optflag("g", "group", "show group as well as user"); + opts.optflag("", "group-directories-first", "list directories before other files"); opts.optflag("h", "header", "show a header row at the top"); opts.optflag("H", "links", "show number of hard links"); opts.optflag("i", "inode", "show each file's inode number"); @@ -87,6 +89,7 @@ impl Options { }; let filter = FileFilter { + list_dirs_first: matches.opt_present("group-directories-first"), reverse: matches.opt_present("reverse"), show_invisibles: matches.opt_present("all"), sort_field: sort_field, @@ -139,6 +142,11 @@ impl FileFilter { if self.reverse { files.reverse(); } + + if self.list_dirs_first { + // This relies on the fact that sort_by is stable. + files.sort_by(|a, b| b.is_directory().cmp(&a.is_directory())); + } } } |