Code style udpates

This commit is contained in:
sharkdp 2017-10-05 21:29:29 +02:00
parent 2403ac350a
commit 34e4620e26
3 changed files with 80 additions and 53 deletions

View File

@ -2,78 +2,106 @@ use clap::{App, AppSettings, Arg};
pub fn build_app() -> App<'static, 'static> {
App::new("fd")
.version(crate_version!())
.usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")
.setting(AppSettings::ColoredHelp)
.setting(AppSettings::DeriveDisplayOrder)
.arg(Arg::with_name("hidden")
.version(crate_version!())
.usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")
.setting(AppSettings::ColoredHelp)
.setting(AppSettings::DeriveDisplayOrder)
.arg(
Arg::with_name("hidden")
.long("hidden")
.short("H")
.help("Search hidden files and directories"))
.arg(Arg::with_name("no-ignore")
.help("Search hidden files and directories"),
)
.arg(
Arg::with_name("no-ignore")
.long("no-ignore")
.short("I")
.help("Do not respect .(git)ignore files"))
.arg(Arg::with_name("case-sensitive")
.help("Do not respect .(git)ignore files"),
)
.arg(
Arg::with_name("case-sensitive")
.long("case-sensitive")
.short("s")
.help("Case-sensitive search (default: smart case)"))
.arg(Arg::with_name("absolute-path")
.help("Case-sensitive search (default: smart case)"),
)
.arg(
Arg::with_name("absolute-path")
.long("absolute-path")
.short("a")
.help("Show absolute instead of relative paths"))
.arg(Arg::with_name("follow")
.help("Show absolute instead of relative paths"),
)
.arg(
Arg::with_name("follow")
.long("follow")
.short("L")
.alias("dereference")
.help("Follow symbolic links"))
.arg(Arg::with_name("full-path")
.help("Follow symbolic links"),
)
.arg(
Arg::with_name("full-path")
.long("full-path")
.short("p")
.help("Search full path (default: file-/dirname only)"))
.arg(Arg::with_name("null_separator")
.help("Search full path (default: file-/dirname only)"),
)
.arg(
Arg::with_name("null_separator")
.long("print0")
.short("0")
.help("Separate results by the null character"))
.arg(Arg::with_name("depth")
.help("Separate results by the null character"),
)
.arg(
Arg::with_name("depth")
.long("max-depth")
.short("d")
.takes_value(true)
.help("Set maximum search depth (default: none)"))
.arg(Arg::with_name("file-type")
.help("Set maximum search depth (default: none)"),
)
.arg(
Arg::with_name("file-type")
.long("type")
.short("t")
.takes_value(true)
.possible_values(&["f", "file", "d", "directory", "s", "symlink"])
.hide_possible_values(true)
.help("Filter by type: f(ile), d(irectory), s(ymlink)"))
.arg(Arg::with_name("extension")
.help("Filter by type: f(ile), d(irectory), s(ymlink)"),
)
.arg(
Arg::with_name("extension")
.long("extension")
.short("e")
.takes_value(true)
.value_name("ext")
.help("Filter by file extension"))
.arg(Arg::with_name("color")
.help("Filter by file extension"),
)
.arg(
Arg::with_name("color")
.long("color")
.short("c")
.takes_value(true)
.possible_values(&["never", "auto", "always"])
.hide_possible_values(true)
.help("When to use color in the output:\n\
never, auto, always (default: auto)"))
.arg(Arg::with_name("threads")
.help(
"When to use color in the output:\n\
never, auto, always (default: auto)",
),
)
.arg(
Arg::with_name("threads")
.long("threads")
.short("j")
.takes_value(true)
.help("Set number of threads to use for searching\n\
(default: number of available CPU cores)"))
.arg(Arg::with_name("max-buffer-time")
.help(
"Set number of threads to use for searching\n\
(default: number of available CPU cores)",
),
)
.arg(
Arg::with_name("max-buffer-time")
.long("max-buffer-time")
.takes_value(true)
.hidden(true)
.help("the time (in ms) to buffer, before streaming to the console"))
.arg(Arg::with_name("pattern")
.help("the search pattern, a regular expression (optional)"))
.arg(Arg::with_name("path")
.help("the root directory for the filesystem search (optional)"))
}
.help("the time (in ms) to buffer, before streaming to the console"),
)
.arg(Arg::with_name("pattern").help("the search pattern, a regular expression (optional)"))
.arg(Arg::with_name("path").help("the root directory for the filesystem search (optional)"))
}

View File

@ -1,7 +1,7 @@
/// A parser for the `LS_COLORS` environment variable.
use std::collections::HashMap;
use ansi_term::{Style, Colour};
use ansi_term::{Colour, Style};
/// Maps file extensions to ANSI colors / styles.
pub type ExtensionStyles = HashMap<String, Style>;
@ -42,7 +42,7 @@ impl Default for LsColors {
symlink: Colour::Cyan.normal(),
executable: Colour::Red.bold(),
extensions: HashMap::new(),
filenames: HashMap::new()
filenames: HashMap::new(),
}
}
}
@ -55,7 +55,7 @@ impl LsColors {
"1" | "01" => Some(Colour::bold),
"3" | "03" => Some(Colour::italic),
"4" | "04" => Some(Colour::underline),
_ => None
_ => None,
}
}

View File

@ -17,7 +17,7 @@ use std::io::Write;
use std::ops::Deref;
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf, Component};
use std::path::{Component, Path, PathBuf};
use std::process;
use std::sync::Arc;
use std::sync::mpsc::channel;
@ -37,7 +37,7 @@ enum PathDisplay {
Absolute,
/// As a relative path
Relative
Relative,
}
/// The type of file to search for.
@ -46,7 +46,7 @@ enum FileType {
Any,
RegularFile,
Directory,
SymLink
SymLink,
}
/// Configuration options for *fd*.
@ -107,14 +107,14 @@ enum ReceiverMode {
Buffering,
/// Receiver is directly printing results to the output.
Streaming
Streaming,
}
/// Root directory
static ROOT_DIR : &'static str = "/";
static ROOT_DIR: &'static str = "/";
/// Parent directory
static PARENT_DIR : &'static str = "..";
static PARENT_DIR: &'static str = "..";
/// Print a search result to the console.
fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) {
@ -129,7 +129,7 @@ fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) {
};
#[cfg(not(target_family = "unix"))]
let is_executable = |_: Option<&std::fs::Metadata>| { false };
let is_executable = |_: Option<&std::fs::Metadata>| false;
let stdout = std::io::stdout();
let mut handle = stdout.lock();
@ -192,9 +192,9 @@ fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) {
}
let r = if config.null_separator {
write!(handle, "\0")
write!(handle, "\0")
} else {
writeln!(handle, "")
writeln!(handle, "")
};
if r.is_err() {
// Probably a broken pipe. Exit gracefully.
@ -237,7 +237,7 @@ fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions>) {
let receiver_thread = thread::spawn(move || {
let start = time::Instant::now();
let mut buffer = vec!();
let mut buffer = vec![];
// Start in buffering mode
let mut mode = ReceiverMode::Buffering;
@ -289,7 +289,7 @@ fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions>) {
Box::new(move |entry_o| {
let entry = match entry_o {
Ok(e) => e,
Err(_) => return ignore::WalkState::Continue
Err(_) => return ignore::WalkState::Continue,
};
// Filter out unwanted file types.
@ -348,8 +348,7 @@ fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions>) {
/// Print error message to stderr and exit with status `1`.
fn error(message: &str) -> ! {
writeln!(&mut std::io::stderr(), "{}", message)
.expect("Failed writing to stderr");
writeln!(&mut std::io::stderr(), "{}", message).expect("Failed writing to stderr");
process::exit(1);
}