mirror of
https://github.com/sharkdp/fd.git
synced 2024-09-28 13:01:30 +02:00
Fix clippy warnings
This commit is contained in:
parent
1430c1d7bf
commit
787e459c90
@ -12,7 +12,6 @@ use std::io::Write;
|
|||||||
use std::path::{Path, Component};
|
use std::path::{Path, Component};
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use ansi_term::Style;
|
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use isatty::stdout_isatty;
|
use isatty::stdout_isatty;
|
||||||
use regex::{Regex, RegexBuilder};
|
use regex::{Regex, RegexBuilder};
|
||||||
@ -70,14 +69,14 @@ fn print_entry(path_root: &Path, path_entry: &Path, config: &FdOptions) {
|
|||||||
.and_then(|n| config.ls_colors.filenames.get(n));
|
.and_then(|n| config.ls_colors.filenames.get(n));
|
||||||
|
|
||||||
match o_style {
|
match o_style {
|
||||||
Some(s) => s.clone(),
|
Some(s) => *s,
|
||||||
None =>
|
None =>
|
||||||
// Look up file extension
|
// Look up file extension
|
||||||
component_path.extension()
|
component_path.extension()
|
||||||
.and_then(|e| e.to_str())
|
.and_then(|e| e.to_str())
|
||||||
.and_then(|e| config.ls_colors.extensions.get(e))
|
.and_then(|e| config.ls_colors.extensions.get(e))
|
||||||
.map(|r| r.clone())
|
.cloned()
|
||||||
.unwrap_or(Style::new())
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -124,7 +123,7 @@ fn scan(root: &Path, pattern: &Regex, config: &FdOptions) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
search_str.and_then(|s| pattern.find(s))
|
search_str.and_then(|s| pattern.find(s))
|
||||||
.map(|_| print_entry(&root, path_rel, &config));
|
.map(|_| print_entry(root, path_rel, config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +162,7 @@ fn main() {
|
|||||||
|
|
||||||
if matches.opt_present("h") {
|
if matches.opt_present("h") {
|
||||||
let brief = "Usage: fd [options] [PATTERN]";
|
let brief = "Usage: fd [options] [PATTERN]";
|
||||||
print!("{}", opts.usage(&brief));
|
print!("{}", opts.usage(brief));
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +182,7 @@ fn main() {
|
|||||||
env::var("LS_COLORS")
|
env::var("LS_COLORS")
|
||||||
.ok()
|
.ok()
|
||||||
.map(|val| LsColors::from_string(&val))
|
.map(|val| LsColors::from_string(&val))
|
||||||
.unwrap_or(LsColors::default());
|
.unwrap_or_default();
|
||||||
|
|
||||||
let config = FdOptions {
|
let config = FdOptions {
|
||||||
// The search will be case-sensitive if the command line flag is set or
|
// The search will be case-sensitive if the command line flag is set or
|
||||||
@ -204,7 +203,7 @@ fn main() {
|
|||||||
match RegexBuilder::new(pattern)
|
match RegexBuilder::new(pattern)
|
||||||
.case_insensitive(!config.case_sensitive)
|
.case_insensitive(!config.case_sensitive)
|
||||||
.build() {
|
.build() {
|
||||||
Ok(re) => scan(¤t_dir, &re, &config),
|
Ok(re) => scan(current_dir, &re, &config),
|
||||||
Err(err) => error(err.description())
|
Err(err) => error(err.description())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ pub struct LsColors {
|
|||||||
pub filenames: FilenameStyles,
|
pub filenames: FilenameStyles,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LsColors {
|
impl Default for LsColors {
|
||||||
/// Get a default LsColors structure.
|
/// Get a default LsColors structure.
|
||||||
pub fn default() -> LsColors {
|
fn default() -> LsColors {
|
||||||
LsColors {
|
LsColors {
|
||||||
directory: Colour::Blue.bold(),
|
directory: Colour::Blue.bold(),
|
||||||
symlink: Colour::Cyan.normal(),
|
symlink: Colour::Cyan.normal(),
|
||||||
@ -32,7 +32,9 @@ impl LsColors {
|
|||||||
filenames: HashMap::new()
|
filenames: HashMap::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LsColors {
|
||||||
fn parse_decoration(code: &str) -> Option<fn(Colour) -> Style> {
|
fn parse_decoration(code: &str) -> Option<fn(Colour) -> Style> {
|
||||||
match code {
|
match code {
|
||||||
"0" | "00" => Some(Colour::normal),
|
"0" | "00" => Some(Colour::normal),
|
||||||
@ -45,7 +47,7 @@ impl LsColors {
|
|||||||
|
|
||||||
/// Parse ANSI escape sequences like `38;5;10;1`.
|
/// Parse ANSI escape sequences like `38;5;10;1`.
|
||||||
fn parse_style(code: &str) -> Option<Style> {
|
fn parse_style(code: &str) -> Option<Style> {
|
||||||
let mut split = code.split(";");
|
let mut split = code.split(';');
|
||||||
|
|
||||||
if let Some(first) = split.next() {
|
if let Some(first) = split.next() {
|
||||||
// Try to match the first part as a text-decoration argument
|
// Try to match the first part as a text-decoration argument
|
||||||
@ -65,26 +67,24 @@ impl LsColors {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Colour::Fixed(n)
|
Colour::Fixed(n)
|
||||||
} else {
|
} else if let Some(color_s) = c1 {
|
||||||
if let Some(color_s) = c1 {
|
match color_s {
|
||||||
match color_s {
|
"30" => Colour::Black,
|
||||||
"30" => Colour::Black,
|
"31" => Colour::Red,
|
||||||
"31" => Colour::Red,
|
"32" => Colour::Green,
|
||||||
"32" => Colour::Green,
|
"33" => Colour::Yellow,
|
||||||
"33" => Colour::Yellow,
|
"34" => Colour::Blue,
|
||||||
"34" => Colour::Blue,
|
"35" => Colour::Purple,
|
||||||
"35" => Colour::Purple,
|
"36" => Colour::Cyan,
|
||||||
"36" => Colour::Cyan,
|
_ => Colour::White
|
||||||
_ => Colour::White
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Colour::White
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Colour::White
|
||||||
};
|
};
|
||||||
|
|
||||||
if decoration.is_none() {
|
if decoration.is_none() {
|
||||||
// Try to find a decoration somewhere in the sequence
|
// Try to find a decoration somewhere in the sequence
|
||||||
decoration = code.split(";")
|
decoration = code.split(';')
|
||||||
.flat_map(LsColors::parse_decoration)
|
.flat_map(LsColors::parse_decoration)
|
||||||
.next();
|
.next();
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ impl LsColors {
|
|||||||
|
|
||||||
/// Add a new LS_COLORS entry
|
/// Add a new LS_COLORS entry
|
||||||
fn add_entry(&mut self, input: &str) {
|
fn add_entry(&mut self, input: &str) {
|
||||||
let mut parts = input.trim().split("=");
|
let mut parts = input.trim().split('=');
|
||||||
if let Some(pattern) = parts.next() {
|
if let Some(pattern) = parts.next() {
|
||||||
if let Some(style_code) = parts.next() {
|
if let Some(style_code) = parts.next() {
|
||||||
// Ensure that the input was split into exactly two parts:
|
// Ensure that the input was split into exactly two parts:
|
||||||
@ -121,7 +121,7 @@ impl LsColors {
|
|||||||
let extension = String::from(pattern).split_off(2);
|
let extension = String::from(pattern).split_off(2);
|
||||||
self.extensions.insert(extension, style);
|
self.extensions.insert(extension, style);
|
||||||
}
|
}
|
||||||
else if pattern.starts_with("*") {
|
else if pattern.starts_with('*') {
|
||||||
let filename = String::from(pattern).split_off(1);
|
let filename = String::from(pattern).split_off(1);
|
||||||
self.filenames.insert(filename, style);
|
self.filenames.insert(filename, style);
|
||||||
} else {
|
} else {
|
||||||
@ -134,11 +134,11 @@ impl LsColors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a `LsColors` structure from a string.
|
/// Generate a `LsColors` structure from a string.
|
||||||
pub fn from_string(input: &String) -> LsColors {
|
pub fn from_string(input: &str) -> LsColors {
|
||||||
let mut lscolors = LsColors::default();
|
let mut lscolors = LsColors::default();
|
||||||
|
|
||||||
for s in input.split(":") {
|
for s in input.split(':') {
|
||||||
lscolors.add_entry(&s);
|
lscolors.add_entry(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
lscolors
|
lscolors
|
||||||
|
Loading…
Reference in New Issue
Block a user