main.rs
This file
Path
src/main.rs
431 lines · 14.8 KiB · Rust
Last changed by
Windows: Check for xterm-256color environment variable as a proxy for color supportsharkdpbefore adoptiona81fef9
History of this fileTake it
The walk stopped after 200 commits: lines older than a0505bd point at it.
Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 1why, one step back1mod app;Clean up include ordersharkdpbefore adoption53557ef
line 2why, one step back2mod error;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 3–4why, one step back3mod exec;4mod exit_codes;Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 5why, one step back5mod filesystem;Move filetypes up from 'internal'sharkdpbefore adoption5c27ab1
line 6why, one step back6mod filetypes;Move filter up from internalsharkdpbefore adoption9f738ad
line 7why, one step back7mod filter;Move FdOptions to Optionssharkdpbefore adoption65096a6
line 8why, one step back8mod options;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 9why, one step back9mod output;Move regex helpers to new modulesharkdpbefore adoption809fd8f
line 10why, one step back10mod regex_helper;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 11–18why, one step back11mod walk;1213use std::env;14use std::path::{Path, PathBuf};15use std::process;16use std::sync::Arc;17use std::time;18Proper error handling in main.rssharkdpbefore adoptionbce9527
line 19why, one step back19use anyhow::{anyhow, Context, Result};Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 20why, one step back20use atty::Stream;--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6
line 21why, one step back21use globset::GlobBuilder;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 22why, one step back22use lscolors::LsColors;Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c
line 23why, one step back23use regex::bytes::{RegexBuilder, RegexSetBuilder};Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 24why, one step back24Allow for missing directoriesDJRHailsbefore adoptionc5a311d
line 25why, one step back25use crate::error::print_error;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 26why, one step back26use crate::exec::CommandTemplate;Proper error handling in main.rssharkdpbefore adoptionbce9527
line 27why, one step back27use crate::exit_codes::ExitCode;Move filetypes up from 'internal'sharkdpbefore adoption5c27ab1
line 28why, one step back28use crate::filetypes::FileTypes;[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024
lines 29–30why, one step back29#[cfg(unix)]30use crate::filter::OwnerFilter;Move filter up from internalsharkdpbefore adoption9f738ad
line 31why, one step back31use crate::filter::{SizeFilter, TimeFilter};Move FdOptions to Optionssharkdpbefore adoption65096a6
line 32why, one step back32use crate::options::Options;Move regex helpers to new modulesharkdpbefore adoption809fd8f
line 33why, one step back33use crate::regex_helper::pattern_has_uppercase_char;Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 34why, one step back34Disable jemallocator on Windowssharkdpbefore adoption4e20803
line 35why, one step back35// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481Disable jemalloc on macOSsharkdpbefore adoption1d1eefd
lines 36–37why, one step back36// FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos37#[cfg(all(not(windows), not(target_os = "macos"), not(target_env = "musl")))]Use jemallocsharkdpbefore adoption5a15486
lines 38–40why, one step back38#[global_allocator]39static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;40Proper error handling in main.rssharkdpbefore adoptionbce9527
line 41why, one step back41fn run() -> Result<ExitCode> {Remove possibility to use '--exec <cmd>' with a single dashsharkdpbefore adoption342d12d
line 42why, one step back42 let matches = app::build_app().get_matches_from(env::args_os());Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 43why, one step back43Allow changing current working directory of fdRafał Hajdackibefore adoptionfb205f5
line 44why, one step back44 // Set the current working directory of the processReimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c
line 45why, one step back45 if let Some(base_directory) = matches.value_of_os("base-directory") {Refactor directory handlingsharkdpbefore adoption094516a
lines 46–47why, one step back46 let base_directory = Path::new(base_directory);47 if !filesystem::is_dir(base_directory) {Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 48–49why, one step back48 return Err(anyhow!(49 "The '--base-directory' path '{}' is not a directory.",Refactor directory handlingsharkdpbefore adoption094516a
line 50why, one step back50 base_directory.to_string_lossy()Proper error handling in main.rssharkdpbefore adoptionbce9527
line 51why, one step back51 ));Allow changing current working directory of fdRafał Hajdackibefore adoptionfb205f5
line 52why, one step back52 }Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 53–58why, one step back53 env::set_current_dir(base_directory).with_context(|| {54 format!(55 "Could not set '{}' as the current working directory.",56 base_directory.to_string_lossy()57 )58 })?;Allow changing current working directory of fdRafał Hajdackibefore adoptionfb205f5
lines 59–60why, one step back59 }60Refactor directory handlingsharkdpbefore adoption094516a
lines 61–62why, one step back61 let current_directory = Path::new(".");62 if !filesystem::is_dir(current_directory) {Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 63–65why, one step back63 return Err(anyhow!(64 "Could not retrieve current directory (has it been deleted?)."65 ));Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 66–67why, one step back66 }67Refactor directory handlingsharkdpbefore adoption094516a
line 68why, one step back68 // Get the search patternReimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c
lines 69–71why, one step back69 let pattern = matches70 .value_of_os("pattern")71 .map(|p| {Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301
lines 72–73why, one step back72 p.to_str()73 .ok_or_else(|| anyhow!("The search pattern includes invalid UTF-8 sequences."))Reimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c
lines 74–76why, one step back74 })75 .transpose()?76 .unwrap_or("");Refactor directory handlingsharkdpbefore adoption094516a
line 77why, one step back77Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 78why, one step back78 // Get one or more root directories to search.Refactor to for-loopDJRHailsbefore adoption4271962
line 79why, one step back79 let passed_arguments = matchesReimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c
line 80why, one step back80 .values_of_os("path")Refactor to for-loopDJRHailsbefore adoption4271962
lines 81–82why, one step back81 .or_else(|| matches.values_of_os("search-path"));82Minor refactoringsharkdpbefore adoption9d3cb69
lines 83–84why, one step back83 let mut search_paths = if let Some(paths) = passed_arguments {84 let mut directories = vec![];Refactor to for-loopDJRHailsbefore adoption4271962
lines 85–87why, one step back85 for path in paths {86 let path_buffer = PathBuf::from(path);87 if filesystem::is_dir(&path_buffer) {Minor refactoringsharkdpbefore adoption9d3cb69
lines 88–89why, one step back88 directories.push(path_buffer);89 } else {Improve consistency of lintingDJRHailsbefore adoptionda9af8c
lines 90–93why, one step back90 print_error(format!(91 "Search path '{}' is not a directory.",92 path_buffer.to_string_lossy()93 ));Refactor to for-loopDJRHailsbefore adoption4271962
lines 94–95why, one step back94 }95 }Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 96why, one step back96Minor refactoringsharkdpbefore adoption9d3cb69
lines 97–101why, one step back97 directories98 } else {99 vec![current_directory.to_path_buf()]100 };101Check for no valid search paths to prevent panicDJRHailsbefore adoption28d6a4f
line 102why, one step back102 // Check if we have no valid search paths.Minor refactoringsharkdpbefore adoption9d3cb69
line 103why, one step back103 if search_paths.is_empty() {Improve consistency of lintingDJRHailsbefore adoptionda9af8c
line 104why, one step back104 return Err(anyhow!("No valid search paths given."));Check for no valid search paths to prevent panicDJRHailsbefore adoption28d6a4f
lines 105–106why, one step back105 }106Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 107why, one step back107 if matches.is_present("absolute-path") {Minor refactoringsharkdpbefore adoption9d3cb69
line 108why, one step back108 search_paths = search_pathsExpose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 109–112why, one step back109 .iter()110 .map(|path_buffer| {111 path_buffer112 .canonicalize()Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 113why, one step back113 .and_then(|pb| filesystem::absolute_path(pb.as_path()))Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 114–121why, one step back114 .unwrap()115 })116 .collect();117 }118119 // Detect if the user accidentally supplied a path instead of a search pattern120 if !matches.is_present("full-path")121 && pattern.contains(std::path::MAIN_SEPARATOR)Rename fshelper to filesystemsharkdpbefore adoptionb415d72
line 122why, one step back122 && filesystem::is_dir(Path::new(pattern))Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 123why, one step back123 {Proper error handling in main.rssharkdpbefore adoptionbce9527
line 124why, one step back124 return Err(anyhow!(Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 125–128why, one step back125 "The search pattern '{pattern}' contains a path-separation character ('{sep}') \126 and will not lead to any search results.\n\n\127 If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \128 fd . '{pattern}'\n\n\Proper error handling in main.rssharkdpbefore adoptionbce9527
line 129why, one step back129 Instead, if you want your pattern to match the full file path, use:\n\n \Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 130–132why, one step back130 fd --full-path '{pattern}'",131 pattern = pattern,132 sep = std::path::MAIN_SEPARATOR,Proper error handling in main.rssharkdpbefore adoptionbce9527
line 133why, one step back133 ));Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 134–135why, one step back134 }135Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301
line 136why, one step back136 let pattern_regex = if matches.is_present("glob") && !pattern.is_empty() {--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6
line 137why, one step back137 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;Implement glob-based searchessharkdpbefore adoptiond5da615
lines 138–140why, one step back138 glob.regex().to_owned()139 } else if matches.is_present("fixed-strings") {140 // Treat pattern as literal string if '--fixed-strings' is usedExpose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 141–150why, one step back141 regex::escape(pattern)142 } else {143 String::from(pattern)144 };145146 // The search will be case-sensitive if the command line flag is set or147 // if the pattern has an uppercase character (smart case).148 let case_sensitive = !matches.is_present("ignore-case")149 && (matches.is_present("case-sensitive") || pattern_has_uppercase_char(&pattern_regex));150Windows: Always enable colors if --color=always is setsharkdpbefore adoption53c338d
line 151why, one step back151 #[cfg(windows)]Windows: Check for xterm-256color environment variable as a proxy for color supportsharkdpbefore adoptiona81fef9
lines 152–153why, one step back152 let ansi_colors_support =153 ansi_term::enable_ansi_support().is_ok() || std::env::var_os("TERM").is_some();Windows: Always enable colors if --color=always is setsharkdpbefore adoption53c338d
lines 154–157why, one step back154155 #[cfg(not(windows))]156 let ansi_colors_support = true;157Print path as raw bytes, allowing invalid UTF-8 filenames to be passed to other processessharkdpbefore adoption6c9e743
line 158why, one step back158 let interactive_terminal = atty::is(Stream::Stdout);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 159–161why, one step back159 let colored_output = match matches.value_of("color") {160 Some("always") => true,161 Some("never") => false,Windows: Always enable colors if --color=always is setsharkdpbefore adoption53c338d
line 162why, one step back162 _ => ansi_colors_support && env::var_os("NO_COLOR").is_none() && interactive_terminal,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 163–164why, one step back163 };164Remove type annotation.Nathan Moreaubefore adoption588e344
line 165why, one step back165 let path_separator = matches.value_of("path-separator").map(|str| str.to_owned());Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 166–172why, one step back166167 let ls_colors = if colored_output {168 Some(LsColors::from_env().unwrap_or_default())169 } else {170 None171 };172Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 173–179why, one step back173 let command = if let Some(args) = matches.values_of("exec") {174 Some(CommandTemplate::new(args))175 } else if let Some(args) = matches.values_of("exec-batch") {176 Some(CommandTemplate::new_batch(args)?)177 } else if matches.is_present("list-details") {178 let color = matches.value_of("color").unwrap_or("auto");179 let color_arg = ["--color=", color].concat();Add `-l`/`--list` optionsharkdpbefore adoptionda5cd12
line 180why, one step back180Add testsharkdpbefore adoption4287cdd
line 181why, one step back181 #[allow(unused)]Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc
lines 182–191why, one step back182 let gnu_ls = |command_name| {183 vec![184 command_name,185 "-l", // long listing format186 "--human-readable", // human readable file sizes187 "--directory", // list directories themselves, not their contents188 &color_arg,189 ]190 };191Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
line 192why, one step back192 let cmd: Vec<&str> = if cfg!(unix) {Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301
lines 193–199why, one step back193 if !cfg!(any(194 target_os = "macos",195 target_os = "dragonfly",196 target_os = "freebsd",197 target_os = "netbsd",198 target_os = "openbsd"199 )) {Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894
line 200why, one step back200 // Assume ls is GNU lsWindows support (if GNU ls is installed)sharkdpbefore adoption0b7febc
line 201why, one step back201 gnu_ls("ls")Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
line 202why, one step back202 } else {Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894
line 203why, one step back203 // MacOS, DragonFlyBSD, FreeBSDDo not show output of 'gls --version'sharkdpbefore adoption0f5500a
line 204why, one step back204 use std::process::{Command, Stdio};Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
line 205why, one step back205Add comment why we prefer glssharkdpbefore adoptiond91100e
line 206why, one step back206 // Use GNU ls, if available (support for --color=auto, better LS_COLORS support)Do not show output of 'gls --version'sharkdpbefore adoption0f5500a
lines 207–212why, one step back207 let gnu_ls_exists = Command::new("gls")208 .arg("--version")209 .stdout(Stdio::null())210 .stderr(Stdio::null())211 .status()212 .is_ok();Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 213–214why, one step back213214 if gnu_ls_exists {Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc
line 215why, one step back215 gnu_ls("gls")Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 216–217why, one step back216 } else {217 let mut cmd = vec![Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894
line 218why, one step back218 "ls", // BSD version of lsAdd MacOS support for -l/--list-detailssharkdpbefore adoption2685728
line 219why, one step back219 "-l", // long listing formatFix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894
line 220why, one step back220 "-h", // '--human-readable' is not available, '-h' isAdd MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 221–223why, one step back221 "-d", // '--directory' is not available, but '-d' is222 ];223Also add NetBSD and OpenBSDTobias Kortkampbefore adoption04bcd54
lines 224–225why, one step back224 if !cfg!(any(target_os = "netbsd", target_os = "openbsd")) && colored_output {225 // -G is not available in NetBSD's and OpenBSD's lsAdd MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 226–231why, one step back226 cmd.push("-G");227 }228229 cmd230 }231 }Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc
lines 232–246why, one step back232 } else if cfg!(windows) {233 use std::process::{Command, Stdio};234235 // Use GNU ls, if available236 let gnu_ls_exists = Command::new("ls")237 .arg("--version")238 .stdout(Stdio::null())239 .stderr(Stdio::null())240 .status()241 .is_ok();242243 if gnu_ls_exists {244 gnu_ls("ls")245 } else {246 return Err(anyhow!(Add testsharkdpbefore adoption4287cdd
line 247why, one step back247 "'fd --list-details' is not supported on Windows unless GNU 'ls' is installed."Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc
lines 248–249why, one step back248 ));249 }Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 250–251why, one step back250 } else {251 return Err(anyhow!(Add testsharkdpbefore adoption4287cdd
line 252why, one step back252 "'fd --list-details' is not supported on this platform."Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728
lines 253–256why, one step back253 ));254 };255256 Some(CommandTemplate::new_batch(&cmd).unwrap())Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 257–259why, one step back257 } else {258 None259 };Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 260why, one step back260Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 261–262why, one step back261 let size_limits = if let Some(vs) = matches.values_of("size") {262 vs.map(|sf| {Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301
lines 263–264why, one step back263 SizeFilter::from_string(sf)264 .ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", sf))Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 265why, one step back265 })Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 266–269why, one step back266 .collect::<Result<Vec<_>>>()?267 } else {268 vec![]269 };Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 270–276why, one step back270271 let now = time::SystemTime::now();272 let mut time_constraints: Vec<TimeFilter> = Vec::new();273 if let Some(t) = matches.value_of("changed-within") {274 if let Some(f) = TimeFilter::after(&now, t) {275 time_constraints.push(f);276 } else {Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 277–280why, one step back277 return Err(anyhow!(278 "'{}' is not a valid date or duration. See 'fd --help'.",279 t280 ));Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 281–286why, one step back281 }282 }283 if let Some(t) = matches.value_of("changed-before") {284 if let Some(f) = TimeFilter::before(&now, t) {285 time_constraints.push(f);286 } else {Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 287–290why, one step back287 return Err(anyhow!(288 "'{}' is not a valid date or duration. See 'fd --help'.",289 t290 ));Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 291–293why, one step back291 }292 }293[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024
lines 294–295why, one step back294 #[cfg(unix)]295 let owner_constraint = if let Some(s) = matches.value_of("owner") {[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
line 296why, one step back296 OwnerFilter::from_string(s)?[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024
lines 297–300why, one step back297 } else {298 None299 };300Move FdOptions to Optionssharkdpbefore adoption65096a6
line 301why, one step back301 let config = Options {Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 302–310why, one step back302 case_sensitive,303 search_full_path: matches.is_present("full-path"),304 ignore_hidden: !(matches.is_present("hidden")305 || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),306 read_fdignore: !(matches.is_present("no-ignore")307 || matches.is_present("rg-alias-hidden-ignore")),308 read_vcsignore: !(matches.is_present("no-ignore")309 || matches.is_present("rg-alias-hidden-ignore")310 || matches.is_present("no-ignore-vcs")),Add global fdignore supportBobbie Soedirgobefore adoption79d5a5b
lines 311–313why, one step back311 read_global_ignore: !(matches.is_present("no-ignore")312 || matches.is_present("rg-alias-hidden-ignore")313 || matches.is_present("no-global-ignore-file")),Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 314why, one step back314 follow_links: matches.is_present("follow"),Rename `--same-file-system` to `--one-file-system`Simon Engmannbefore adoption94993ca
line 315why, one step back315 one_file_system: matches.is_present("one-file-system"),Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 316–317why, one step back316 null_separator: matches.is_present("null_separator"),317 max_depth: matchesAdd --min-depth and --exact-depthsharkdpbefore adoptiond63c63b
line 318why, one step back318 .value_of("max-depth")Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 319why, one step back319 .or_else(|| matches.value_of("rg-depth"))Add --min-depth and --exact-depthsharkdpbefore adoptiond63c63b
lines 320–324why, one step back320 .or_else(|| matches.value_of("exact-depth"))321 .and_then(|n| usize::from_str_radix(n, 10).ok()),322 min_depth: matches323 .value_of("min-depth")324 .or_else(|| matches.value_of("exact-depth"))Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 325–337why, one step back325 .and_then(|n| usize::from_str_radix(n, 10).ok()),326 threads: std::cmp::max(327 matches328 .value_of("threads")329 .and_then(|n| usize::from_str_radix(n, 10).ok())330 .unwrap_or_else(num_cpus::get),331 1,332 ),333 max_buffer_time: matches334 .value_of("max-buffer-time")335 .and_then(|n| u64::from_str_radix(n, 10).ok())336 .map(time::Duration::from_millis),337 ls_colors,Print path as raw bytes, allowing invalid UTF-8 filenames to be passed to other processessharkdpbefore adoption6c9e743
line 338why, one step back338 interactive_terminal,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 339–349why, one step back339 file_types: matches.values_of("file-type").map(|values| {340 let mut file_types = FileTypes::default();341 for value in values {342 match value {343 "f" | "file" => file_types.files = true,344 "d" | "directory" => file_types.directories = true,345 "l" | "symlink" => file_types.symlinks = true,346 "x" | "executable" => {347 file_types.executables_only = true;348 file_types.files = true;349 }Add new `--type socket` and `--type pipe` filterssharkdpbefore adoptioncb56add
lines 350–352why, one step back350 "e" | "empty" => file_types.empty_only = true,351 "s" | "socket" => file_types.sockets = true,352 "p" | "pipe" => file_types.pipes = true,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 353–364why, one step back353 _ => unreachable!(),354 }355 }356357 // If only 'empty' was specified, search for both files and directories:358 if file_types.empty_only && !(file_types.files || file_types.directories) {359 file_types.files = true;360 file_types.directories = true;361 }362363 file_types364 }),Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 365–375why, one step back365 extensions: matches366 .values_of("extension")367 .map(|exts| {368 let patterns = exts369 .map(|e| e.trim_start_matches('.'))370 .map(|e| format!(r".\.{}$", regex::escape(e)));371 RegexSetBuilder::new(patterns)372 .case_insensitive(true)373 .build()374 })375 .transpose()?,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 376–386why, one step back376 command: command.map(Arc::new),377 exclude_patterns: matches378 .values_of("exclude")379 .map(|v| v.map(|p| String::from("!") + p).collect())380 .unwrap_or_else(|| vec![]),381 ignore_files: matches382 .values_of("ignore-file")383 .map(|vs| vs.map(PathBuf::from).collect())384 .unwrap_or_else(|| vec![]),385 size_constraints: size_limits,386 time_constraints,[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024
lines 387–388why, one step back387 #[cfg(unix)]388 owner_constraint,Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 389why, one step back389 show_filesystem_errors: matches.is_present("show-errors"),Add path-separator option.Nathan Moreaubefore adoption24e108e
line 390why, one step back390 path_separator,Add --max-results=<count> optionsharkdpbefore adoptiond43827f
lines 391–393why, one step back391 max_results: matches392 .value_of("max-results")393 .and_then(|n| usize::from_str_radix(n, 10).ok())Add alias -1 for --max-results=1Danny Möschbefore adoption2bab4a2
line 394why, one step back394 .filter(|&n| n != 0)--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6
lines 395–401why, one step back395 .or_else(|| {396 if matches.is_present("max-one-result") {397 Some(1)398 } else {399 None400 }401 }),Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 402–403why, one step back402 };403Proper error handling in main.rssharkdpbefore adoptionbce9527
line 404why, one step back404 let re = RegexBuilder::new(&pattern_regex)Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 405–407why, one step back405 .case_insensitive(!config.case_sensitive)406 .dot_matches_new_line(true)407 .build()Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 408–416why, one step back408 .map_err(|e| {409 anyhow!(410 "{}\n\nNote: You can use the '--fixed-strings' option to search for a \411 literal string instead of a regular expression. Alternatively, you can \412 also use the '--glob' option to match on a glob pattern.",413 e.to_string()414 )415 })?;416Minor refactoringsharkdpbefore adoption9d3cb69
line 417why, one step back417 walk::scan(&search_paths, Arc::new(re), Arc::new(config))Proper error handling in main.rssharkdpbefore adoptionbce9527
lines 418–423why, one step back418}419420fn main() {421 let result = run();422 match result {423 Ok(exit_code) => {Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 424–426why, one step back424 process::exit(exit_code.into());425 }426 Err(err) => {Proper error handling in main.rssharkdpbefore adoptionbce9527
line 427why, one step back427 eprintln!("[fd error]: {}", err);Remove process::exit instancesharkdpbefore adoption4815ee4
line 428why, one step back428 process::exit(ExitCode::GeneralError.into());Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 429–431why, one step back429 }430 }431}