Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch origin/option-pars-ng
This merges in exa’s own new options parser, which has the following features: - You can specify an option twice and it’ll use the second one, making aliases usable for defaults (fixes #144) - Lets arguments be specified more than once (fixes #125) Strict mode is not done yet; I just wanted to merge this in because it’s been a while, and there’s work that needs to be done on master so I don’t want them drifting apart any further. It’s likely that you’ll find cases where multiple arguments doesn’t work or where the wrong value is being used. There aren’t tests for *everything* yet, and it still uses global environment variables. # Conflicts: # src/options/view.rs
- Loading branch information
Showing
20 changed files
with
1,679 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ license = "MIT" | |
[[bin]] | ||
name = "exa" | ||
path = "src/bin/main.rs" | ||
doc = false | ||
|
||
[lib] | ||
name = "exa" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// What to do when encountering a directory? | ||
#[derive(PartialEq, Debug, Copy, Clone)] | ||
pub enum DirAction { | ||
|
||
/// This directory should be listed along with the regular files, instead | ||
/// of having its contents queried. | ||
AsFile, | ||
|
||
/// This directory should not be listed, and should instead be opened and | ||
/// *its* files listed separately. This is the default behaviour. | ||
List, | ||
|
||
/// This directory should be listed along with the regular files, and then | ||
/// its contents should be listed afterward. The recursive contents of | ||
/// *those* contents are dictated by the options argument. | ||
Recurse(RecurseOptions), | ||
} | ||
|
||
impl DirAction { | ||
|
||
/// Gets the recurse options, if this dir action has any. | ||
pub fn recurse_options(&self) -> Option<RecurseOptions> { | ||
match *self { | ||
DirAction::Recurse(opts) => Some(opts), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Whether to treat directories as regular files or not. | ||
pub fn treat_dirs_as_files(&self) -> bool { | ||
match *self { | ||
DirAction::AsFile => true, | ||
DirAction::Recurse(RecurseOptions { tree, .. }) => tree, | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
|
||
/// The options that determine how to recurse into a directory. | ||
#[derive(PartialEq, Debug, Copy, Clone)] | ||
pub struct RecurseOptions { | ||
|
||
/// Whether recursion should be done as a tree or as multiple individual | ||
/// views of files. | ||
pub tree: bool, | ||
|
||
/// The maximum number of times that recursion should descend to, if one | ||
/// is specified. | ||
pub max_depth: Option<usize>, | ||
} | ||
|
||
impl RecurseOptions { | ||
|
||
/// Returns whether a directory of the given depth would be too deep. | ||
pub fn is_too_deep(&self, depth: usize) -> bool { | ||
match self.max_depth { | ||
None => false, | ||
Some(d) => { | ||
d <= depth | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.