mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-27 23:58:25 +00:00
Remove some enum glob imports
These are holdovers from how I used to write Rust ("back in the day" of 2014). There are still some places in the code where I think it's worth glob-importing enums, but not these places.
This commit is contained in:
parent
f0c139ca68
commit
a25cfe765d
@ -123,20 +123,19 @@ impl GitRepo {
|
||||
/// repository is moved out, but before the results have been moved in!
|
||||
/// See https://stackoverflow.com/q/45985827/3484614
|
||||
fn search(&self, index: &Path, prefix_lookup: bool) -> f::Git {
|
||||
use self::GitContents::*;
|
||||
use std::mem::replace;
|
||||
|
||||
let mut contents = self.contents.lock().unwrap();
|
||||
if let After { ref statuses } = *contents {
|
||||
if let GitContents::After { ref statuses } = *contents {
|
||||
debug!("Git repo {:?} has been found in cache", &self.workdir);
|
||||
return statuses.status(index, prefix_lookup);
|
||||
}
|
||||
|
||||
debug!("Querying Git repo {:?} for the first time", &self.workdir);
|
||||
let repo = replace(&mut *contents, Processing).inner_repo();
|
||||
let repo = replace(&mut *contents, GitContents::Processing).inner_repo();
|
||||
let statuses = repo_to_statuses(&repo, &self.workdir);
|
||||
let result = statuses.status(index, prefix_lookup);
|
||||
let _processing = replace(&mut *contents, After { statuses });
|
||||
let _processing = replace(&mut *contents, GitContents::After { statuses });
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,6 @@ impl Args {
|
||||
pub fn parse<'args, I>(&self, inputs: I, strictness: Strictness) -> Result<Matches<'args>, ParseError>
|
||||
where I: IntoIterator<Item=&'args OsString> {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use self::TakesValue::*;
|
||||
|
||||
let mut parsing = true;
|
||||
|
||||
@ -183,8 +182,9 @@ impl Args {
|
||||
let arg = self.lookup_long(before)?;
|
||||
let flag = Flag::Long(arg.long);
|
||||
match arg.takes_value {
|
||||
Necessary(_)|Optional(_) => result_flags.push((flag, Some(after))),
|
||||
Forbidden => return Err(ParseError::ForbiddenValue { flag })
|
||||
TakesValue::Necessary(_) |
|
||||
TakesValue::Optional(_) => result_flags.push((flag, Some(after))),
|
||||
TakesValue::Forbidden => return Err(ParseError::ForbiddenValue { flag }),
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,16 +194,18 @@ impl Args {
|
||||
let arg = self.lookup_long(long_arg_name)?;
|
||||
let flag = Flag::Long(arg.long);
|
||||
match arg.takes_value {
|
||||
Forbidden => result_flags.push((flag, None)),
|
||||
Necessary(values) => {
|
||||
TakesValue::Forbidden => {
|
||||
result_flags.push((flag, None))
|
||||
}
|
||||
TakesValue::Necessary(values) => {
|
||||
if let Some(next_arg) = inputs.next() {
|
||||
result_flags.push((flag, Some(next_arg)));
|
||||
}
|
||||
else {
|
||||
return Err(ParseError::NeedsValue { flag, values })
|
||||
}
|
||||
},
|
||||
Optional(_) => {
|
||||
}
|
||||
TakesValue::Optional(_) => {
|
||||
if let Some(next_arg) = inputs.next() {
|
||||
result_flags.push((flag, Some(next_arg)));
|
||||
}
|
||||
@ -240,8 +242,13 @@ impl Args {
|
||||
let arg = self.lookup_short(*byte)?;
|
||||
let flag = Flag::Short(*byte);
|
||||
match arg.takes_value {
|
||||
Forbidden|Optional(_) => result_flags.push((flag, None)),
|
||||
Necessary(values) => return Err(ParseError::NeedsValue { flag, values })
|
||||
TakesValue::Forbidden |
|
||||
TakesValue::Optional(_) => {
|
||||
result_flags.push((flag, None));
|
||||
}
|
||||
TakesValue::Necessary(values) => {
|
||||
return Err(ParseError::NeedsValue { flag, values });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,8 +256,13 @@ impl Args {
|
||||
let arg = self.lookup_short(*arg_with_value)?;
|
||||
let flag = Flag::Short(arg.short.unwrap());
|
||||
match arg.takes_value {
|
||||
Necessary(_)|Optional(_) => result_flags.push((flag, Some(after))),
|
||||
Forbidden => return Err(ParseError::ForbiddenValue { flag })
|
||||
TakesValue::Necessary(_) |
|
||||
TakesValue::Optional(_) => {
|
||||
result_flags.push((flag, Some(after)));
|
||||
}
|
||||
TakesValue::Forbidden => {
|
||||
return Err(ParseError::ForbiddenValue { flag });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,8 +283,11 @@ impl Args {
|
||||
let arg = self.lookup_short(*byte)?;
|
||||
let flag = Flag::Short(*byte);
|
||||
match arg.takes_value {
|
||||
Forbidden => result_flags.push((flag, None)),
|
||||
Necessary(values)|Optional(values) => {
|
||||
TakesValue::Forbidden => {
|
||||
result_flags.push((flag, None))
|
||||
}
|
||||
TakesValue::Necessary(values) |
|
||||
TakesValue::Optional(values) => {
|
||||
if index < bytes.len() - 1 {
|
||||
let remnants = &bytes[index+1 ..];
|
||||
result_flags.push((flag, Some(OsStr::from_bytes(remnants))));
|
||||
@ -283,11 +298,13 @@ impl Args {
|
||||
}
|
||||
else {
|
||||
match arg.takes_value {
|
||||
Forbidden => unreachable!(),
|
||||
Necessary(_) => {
|
||||
TakesValue::Forbidden => {
|
||||
unreachable!()
|
||||
}
|
||||
TakesValue::Necessary(_) => {
|
||||
return Err(ParseError::NeedsValue { flag, values });
|
||||
},
|
||||
Optional(_) => {
|
||||
}
|
||||
TakesValue::Optional(_) => {
|
||||
result_flags.push((flag, None));
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ impl Styles {
|
||||
#[allow(trivial_casts)] // the "as Box<_>" stuff below warns about this for some reason
|
||||
pub fn deduce<V, TW>(matches: &MatchedFlags, vars: &V, widther: TW) -> Result<Self, Misfire>
|
||||
where TW: Fn() -> Option<usize>, V: Vars {
|
||||
use self::TerminalColours::*;
|
||||
use crate::info::filetype::FileExtensions;
|
||||
use crate::output::file_name::NoFileColours;
|
||||
|
||||
@ -89,7 +88,10 @@ impl Styles {
|
||||
// Before we do anything else, figure out if we need to consider
|
||||
// custom colours at all
|
||||
let tc = TerminalColours::deduce(matches)?;
|
||||
if tc == Never || (tc == Automatic && widther().is_none()) {
|
||||
|
||||
if tc == TerminalColours::Never
|
||||
|| (tc == TerminalColours::Automatic && widther().is_none())
|
||||
{
|
||||
return Ok(Self {
|
||||
colours: Colours::plain(),
|
||||
style: FileStyle { classify, exts: Box::new(NoFileColours) },
|
||||
|
@ -27,14 +27,12 @@ impl Mode {
|
||||
|
||||
/// Determine the mode from the command-line arguments.
|
||||
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> {
|
||||
use crate::options::misfire::Misfire::*;
|
||||
|
||||
let long = || {
|
||||
if matches.has(&flags::ACROSS)? && !matches.has(&flags::GRID)? {
|
||||
Err(Useless(&flags::ACROSS, true, &flags::LONG))
|
||||
Err(Misfire::Useless(&flags::ACROSS, true, &flags::LONG))
|
||||
}
|
||||
else if matches.has(&flags::ONE_LINE)? {
|
||||
Err(Useless(&flags::ONE_LINE, true, &flags::LONG))
|
||||
Err(Misfire::Useless(&flags::ONE_LINE, true, &flags::LONG))
|
||||
}
|
||||
else {
|
||||
Ok(details::Options {
|
||||
@ -50,7 +48,7 @@ impl Mode {
|
||||
if let Some(width) = TerminalWidth::deduce(vars)?.width() {
|
||||
if matches.has(&flags::ONE_LINE)? {
|
||||
if matches.has(&flags::ACROSS)? {
|
||||
Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE))
|
||||
Err(Misfire::Useless(&flags::ACROSS, true, &flags::ONE_LINE))
|
||||
}
|
||||
else {
|
||||
let lines = lines::Options { icons: matches.has(&flags::ICONS)? };
|
||||
@ -123,17 +121,17 @@ impl Mode {
|
||||
for option in &[ &flags::BINARY, &flags::BYTES, &flags::INODE, &flags::LINKS,
|
||||
&flags::HEADER, &flags::BLOCKS, &flags::TIME, &flags::GROUP ] {
|
||||
if matches.has(option)? {
|
||||
return Err(Useless(*option, false, &flags::LONG));
|
||||
return Err(Misfire::Useless(*option, false, &flags::LONG));
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(feature="git") && matches.has(&flags::GIT)? {
|
||||
return Err(Useless(&flags::GIT, false, &flags::LONG));
|
||||
return Err(Misfire::Useless(&flags::GIT, false, &flags::LONG));
|
||||
}
|
||||
else if matches.has(&flags::LEVEL)? && !matches.has(&flags::RECURSE)? && !matches.has(&flags::TREE)? {
|
||||
// TODO: I'm not sure if the code even gets this far.
|
||||
// There is an identical check in dir_action
|
||||
return Err(Useless2(&flags::LEVEL, &flags::RECURSE, &flags::TREE));
|
||||
return Err(Misfire::Useless2(&flags::LEVEL, &flags::RECURSE, &flags::TREE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,8 +367,6 @@ impl<'a, 'f> Table<'a> {
|
||||
}
|
||||
|
||||
fn display(&self, file: &File, column: Column, xattrs: bool) -> TextCell {
|
||||
use crate::output::table::TimeType::*;
|
||||
|
||||
match column {
|
||||
Column::Permissions => self.permissions_plus(file, xattrs).render(self.colours),
|
||||
Column::FileSize => file.size().render(self.colours, self.size_format, &self.env.numeric),
|
||||
@ -380,10 +378,10 @@ impl<'a, 'f> Table<'a> {
|
||||
Column::GitStatus => self.git_status(file).render(self.colours),
|
||||
Column::Octal => self.octal_permissions(file).render(self.colours.octal),
|
||||
|
||||
Column::Timestamp(Modified) => file.modified_time().render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(Changed) => file.changed_time() .render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(Created) => file.created_time() .render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(Accessed) => file.accessed_time().render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(TimeType::Modified) => file.modified_time().render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(TimeType::Changed) => file.changed_time() .render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(TimeType::Created) => file.created_time() .render(self.colours.date, &self.env.tz, self.time_format),
|
||||
Column::Timestamp(TimeType::Accessed) => file.accessed_time().render(self.colours.date, &self.env.tz, self.time_format),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,6 +431,7 @@ impl render::PermissionsColours for Colours {
|
||||
impl render::SizeColours for Colours {
|
||||
fn size(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||
use number_prefix::Prefix::*;
|
||||
|
||||
match prefix {
|
||||
None => self.size.number_byte,
|
||||
Some(Kilo) | Some(Kibi) => self.size.number_kilo,
|
||||
@ -442,6 +443,7 @@ impl render::SizeColours for Colours {
|
||||
|
||||
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||
use number_prefix::Prefix::*;
|
||||
|
||||
match prefix {
|
||||
None => self.size.unit_byte,
|
||||
Some(Kilo) | Some(Kibi) => self.size.unit_kilo,
|
||||
|
Loading…
x
Reference in New Issue
Block a user