mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-29 16:48: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!
|
/// repository is moved out, but before the results have been moved in!
|
||||||
/// See https://stackoverflow.com/q/45985827/3484614
|
/// See https://stackoverflow.com/q/45985827/3484614
|
||||||
fn search(&self, index: &Path, prefix_lookup: bool) -> f::Git {
|
fn search(&self, index: &Path, prefix_lookup: bool) -> f::Git {
|
||||||
use self::GitContents::*;
|
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
|
|
||||||
let mut contents = self.contents.lock().unwrap();
|
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);
|
debug!("Git repo {:?} has been found in cache", &self.workdir);
|
||||||
return statuses.status(index, prefix_lookup);
|
return statuses.status(index, prefix_lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Querying Git repo {:?} for the first time", &self.workdir);
|
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 statuses = repo_to_statuses(&repo, &self.workdir);
|
||||||
let result = statuses.status(index, prefix_lookup);
|
let result = statuses.status(index, prefix_lookup);
|
||||||
let _processing = replace(&mut *contents, After { statuses });
|
let _processing = replace(&mut *contents, GitContents::After { statuses });
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,6 @@ impl Args {
|
|||||||
pub fn parse<'args, I>(&self, inputs: I, strictness: Strictness) -> Result<Matches<'args>, ParseError>
|
pub fn parse<'args, I>(&self, inputs: I, strictness: Strictness) -> Result<Matches<'args>, ParseError>
|
||||||
where I: IntoIterator<Item=&'args OsString> {
|
where I: IntoIterator<Item=&'args OsString> {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use self::TakesValue::*;
|
|
||||||
|
|
||||||
let mut parsing = true;
|
let mut parsing = true;
|
||||||
|
|
||||||
@ -183,8 +182,9 @@ impl Args {
|
|||||||
let arg = self.lookup_long(before)?;
|
let arg = self.lookup_long(before)?;
|
||||||
let flag = Flag::Long(arg.long);
|
let flag = Flag::Long(arg.long);
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Necessary(_)|Optional(_) => result_flags.push((flag, Some(after))),
|
TakesValue::Necessary(_) |
|
||||||
Forbidden => return Err(ParseError::ForbiddenValue { flag })
|
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 arg = self.lookup_long(long_arg_name)?;
|
||||||
let flag = Flag::Long(arg.long);
|
let flag = Flag::Long(arg.long);
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Forbidden => result_flags.push((flag, None)),
|
TakesValue::Forbidden => {
|
||||||
Necessary(values) => {
|
result_flags.push((flag, None))
|
||||||
|
}
|
||||||
|
TakesValue::Necessary(values) => {
|
||||||
if let Some(next_arg) = inputs.next() {
|
if let Some(next_arg) = inputs.next() {
|
||||||
result_flags.push((flag, Some(next_arg)));
|
result_flags.push((flag, Some(next_arg)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Err(ParseError::NeedsValue { flag, values })
|
return Err(ParseError::NeedsValue { flag, values })
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Optional(_) => {
|
TakesValue::Optional(_) => {
|
||||||
if let Some(next_arg) = inputs.next() {
|
if let Some(next_arg) = inputs.next() {
|
||||||
result_flags.push((flag, Some(next_arg)));
|
result_flags.push((flag, Some(next_arg)));
|
||||||
}
|
}
|
||||||
@ -240,8 +242,13 @@ impl Args {
|
|||||||
let arg = self.lookup_short(*byte)?;
|
let arg = self.lookup_short(*byte)?;
|
||||||
let flag = Flag::Short(*byte);
|
let flag = Flag::Short(*byte);
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Forbidden|Optional(_) => result_flags.push((flag, None)),
|
TakesValue::Forbidden |
|
||||||
Necessary(values) => return Err(ParseError::NeedsValue { flag, values })
|
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 arg = self.lookup_short(*arg_with_value)?;
|
||||||
let flag = Flag::Short(arg.short.unwrap());
|
let flag = Flag::Short(arg.short.unwrap());
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Necessary(_)|Optional(_) => result_flags.push((flag, Some(after))),
|
TakesValue::Necessary(_) |
|
||||||
Forbidden => return Err(ParseError::ForbiddenValue { flag })
|
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 arg = self.lookup_short(*byte)?;
|
||||||
let flag = Flag::Short(*byte);
|
let flag = Flag::Short(*byte);
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Forbidden => result_flags.push((flag, None)),
|
TakesValue::Forbidden => {
|
||||||
Necessary(values)|Optional(values) => {
|
result_flags.push((flag, None))
|
||||||
|
}
|
||||||
|
TakesValue::Necessary(values) |
|
||||||
|
TakesValue::Optional(values) => {
|
||||||
if index < bytes.len() - 1 {
|
if index < bytes.len() - 1 {
|
||||||
let remnants = &bytes[index+1 ..];
|
let remnants = &bytes[index+1 ..];
|
||||||
result_flags.push((flag, Some(OsStr::from_bytes(remnants))));
|
result_flags.push((flag, Some(OsStr::from_bytes(remnants))));
|
||||||
@ -283,11 +298,13 @@ impl Args {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
match arg.takes_value {
|
match arg.takes_value {
|
||||||
Forbidden => unreachable!(),
|
TakesValue::Forbidden => {
|
||||||
Necessary(_) => {
|
unreachable!()
|
||||||
|
}
|
||||||
|
TakesValue::Necessary(_) => {
|
||||||
return Err(ParseError::NeedsValue { flag, values });
|
return Err(ParseError::NeedsValue { flag, values });
|
||||||
},
|
}
|
||||||
Optional(_) => {
|
TakesValue::Optional(_) => {
|
||||||
result_flags.push((flag, None));
|
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
|
#[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>
|
pub fn deduce<V, TW>(matches: &MatchedFlags, vars: &V, widther: TW) -> Result<Self, Misfire>
|
||||||
where TW: Fn() -> Option<usize>, V: Vars {
|
where TW: Fn() -> Option<usize>, V: Vars {
|
||||||
use self::TerminalColours::*;
|
|
||||||
use crate::info::filetype::FileExtensions;
|
use crate::info::filetype::FileExtensions;
|
||||||
use crate::output::file_name::NoFileColours;
|
use crate::output::file_name::NoFileColours;
|
||||||
|
|
||||||
@ -89,7 +88,10 @@ impl Styles {
|
|||||||
// Before we do anything else, figure out if we need to consider
|
// Before we do anything else, figure out if we need to consider
|
||||||
// custom colours at all
|
// custom colours at all
|
||||||
let tc = TerminalColours::deduce(matches)?;
|
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 {
|
return Ok(Self {
|
||||||
colours: Colours::plain(),
|
colours: Colours::plain(),
|
||||||
style: FileStyle { classify, exts: Box::new(NoFileColours) },
|
style: FileStyle { classify, exts: Box::new(NoFileColours) },
|
||||||
|
@ -27,14 +27,12 @@ impl Mode {
|
|||||||
|
|
||||||
/// Determine the mode from the command-line arguments.
|
/// Determine the mode from the command-line arguments.
|
||||||
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> {
|
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> {
|
||||||
use crate::options::misfire::Misfire::*;
|
|
||||||
|
|
||||||
let long = || {
|
let long = || {
|
||||||
if matches.has(&flags::ACROSS)? && !matches.has(&flags::GRID)? {
|
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)? {
|
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 {
|
else {
|
||||||
Ok(details::Options {
|
Ok(details::Options {
|
||||||
@ -50,7 +48,7 @@ impl Mode {
|
|||||||
if let Some(width) = TerminalWidth::deduce(vars)?.width() {
|
if let Some(width) = TerminalWidth::deduce(vars)?.width() {
|
||||||
if matches.has(&flags::ONE_LINE)? {
|
if matches.has(&flags::ONE_LINE)? {
|
||||||
if matches.has(&flags::ACROSS)? {
|
if matches.has(&flags::ACROSS)? {
|
||||||
Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE))
|
Err(Misfire::Useless(&flags::ACROSS, true, &flags::ONE_LINE))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let lines = lines::Options { icons: matches.has(&flags::ICONS)? };
|
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,
|
for option in &[ &flags::BINARY, &flags::BYTES, &flags::INODE, &flags::LINKS,
|
||||||
&flags::HEADER, &flags::BLOCKS, &flags::TIME, &flags::GROUP ] {
|
&flags::HEADER, &flags::BLOCKS, &flags::TIME, &flags::GROUP ] {
|
||||||
if matches.has(option)? {
|
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)? {
|
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)? {
|
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.
|
// TODO: I'm not sure if the code even gets this far.
|
||||||
// There is an identical check in dir_action
|
// 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 {
|
fn display(&self, file: &File, column: Column, xattrs: bool) -> TextCell {
|
||||||
use crate::output::table::TimeType::*;
|
|
||||||
|
|
||||||
match column {
|
match column {
|
||||||
Column::Permissions => self.permissions_plus(file, xattrs).render(self.colours),
|
Column::Permissions => self.permissions_plus(file, xattrs).render(self.colours),
|
||||||
Column::FileSize => file.size().render(self.colours, self.size_format, &self.env.numeric),
|
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::GitStatus => self.git_status(file).render(self.colours),
|
||||||
Column::Octal => self.octal_permissions(file).render(self.colours.octal),
|
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(TimeType::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(TimeType::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(TimeType::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::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 {
|
impl render::SizeColours for Colours {
|
||||||
fn size(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
fn size(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::*;
|
||||||
|
|
||||||
match prefix {
|
match prefix {
|
||||||
None => self.size.number_byte,
|
None => self.size.number_byte,
|
||||||
Some(Kilo) | Some(Kibi) => self.size.number_kilo,
|
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 {
|
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::*;
|
||||||
|
|
||||||
match prefix {
|
match prefix {
|
||||||
None => self.size.unit_byte,
|
None => self.size.unit_byte,
|
||||||
Some(Kilo) | Some(Kibi) => self.size.unit_kilo,
|
Some(Kilo) | Some(Kibi) => self.size.unit_kilo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user