Skip to content
Myr

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 file

Take 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 back
1mod app;

Clean up include ordersharkdpbefore adoption53557ef

line 2why, one step back
2mod error;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 3–4why, one step back
3mod exec;
4mod exit_codes;

Rename fshelper to filesystemsharkdpbefore adoptionb415d72

line 5why, one step back
5mod filesystem;

Move filetypes up from 'internal'sharkdpbefore adoption5c27ab1

line 6why, one step back
6mod filetypes;

Move filter up from internalsharkdpbefore adoption9f738ad

line 7why, one step back
7mod filter;

Move FdOptions to Optionssharkdpbefore adoption65096a6

line 8why, one step back
8mod options;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 9why, one step back
9mod output;

Move regex helpers to new modulesharkdpbefore adoption809fd8f

line 10why, one step back
10mod regex_helper;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 11–18why, one step back
11mod walk;
1213use std::env;14use std::path::{Path, PathBuf};15use std::process;16use std::sync::Arc;17use std::time;18

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 19why, one step back
19use anyhow::{anyhow, Context, Result};

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 20why, one step back
20use atty::Stream;

--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6

line 21why, one step back
21use globset::GlobBuilder;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 22why, one step back
22use lscolors::LsColors;

Use regex::bytes::* instead of regex::*sharkdpbefore adoption641594c

line 23why, one step back
23use regex::bytes::{RegexBuilder, RegexSetBuilder};

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 24why, one step back
24

Allow for missing directoriesDJRHailsbefore adoptionc5a311d

line 25why, one step back
25use crate::error::print_error;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 26why, one step back
26use crate::exec::CommandTemplate;

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 27why, one step back
27use crate::exit_codes::ExitCode;

Move filetypes up from 'internal'sharkdpbefore adoption5c27ab1

line 28why, one step back
28use crate::filetypes::FileTypes;

[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024

lines 29–30why, one step back
29#[cfg(unix)]
30use crate::filter::OwnerFilter;

Move filter up from internalsharkdpbefore adoption9f738ad

line 31why, one step back
31use crate::filter::{SizeFilter, TimeFilter};

Move FdOptions to Optionssharkdpbefore adoption65096a6

line 32why, one step back
32use crate::options::Options;

Move regex helpers to new modulesharkdpbefore adoption809fd8f

line 33why, one step back
33use crate::regex_helper::pattern_has_uppercase_char;

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 34why, one step back
34

Disable jemallocator on Windowssharkdpbefore adoption4e20803

line 35why, one step back
35// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481

Disable jemalloc on macOSsharkdpbefore adoption1d1eefd

lines 36–37why, one step back
36// FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos
37#[cfg(all(not(windows), not(target_os = "macos"), not(target_env = "musl")))]

Use jemallocsharkdpbefore adoption5a15486

lines 38–40why, one step back
38#[global_allocator]
39static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;40

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 41why, one step back
41fn run() -> Result<ExitCode> {

Remove possibility to use '--exec <cmd>' with a single dashsharkdpbefore adoption342d12d

line 42why, one step back
42 let matches = app::build_app().get_matches_from(env::args_os());

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 43why, one step back
43

Allow changing current working directory of fdRafał Hajdackibefore adoptionfb205f5

line 44why, one step back
44 // Set the current working directory of the process

Reimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c

line 45why, one step back
45 if let Some(base_directory) = matches.value_of_os("base-directory") {

Refactor directory handlingsharkdpbefore adoption094516a

lines 46–47why, one step back
46 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 back
48 return Err(anyhow!(
49 "The '--base-directory' path '{}' is not a directory.",

Refactor directory handlingsharkdpbefore adoption094516a

line 50why, one step back
50 base_directory.to_string_lossy()

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 51why, one step back
51 ));

Allow changing current working directory of fdRafał Hajdackibefore adoptionfb205f5

line 52why, one step back
52 }

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 53–58why, one step back
53 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 back
59 }
60

Refactor directory handlingsharkdpbefore adoption094516a

lines 61–62why, one step back
61 let current_directory = Path::new(".");
62 if !filesystem::is_dir(current_directory) {

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 63–65why, one step back
63 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 back
66 }
67

Refactor directory handlingsharkdpbefore adoption094516a

line 68why, one step back
68 // Get the search pattern

Reimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c

lines 69–71why, one step back
69 let pattern = matches
70 .value_of_os("pattern")71 .map(|p| {

Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301

lines 72–73why, one step back
72 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 back
74 })
75 .transpose()?76 .unwrap_or("");

Refactor directory handlingsharkdpbefore adoption094516a

line 77why, one step back
77

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 78why, one step back
78 // Get one or more root directories to search.

Refactor to for-loopDJRHailsbefore adoption4271962

line 79why, one step back
79 let passed_arguments = matches

Reimplement dirname, basename, remove_extension for OsStrsharkdpbefore adoption7e3c69c

line 80why, one step back
80 .values_of_os("path")

Refactor to for-loopDJRHailsbefore adoption4271962

lines 81–82why, one step back
81 .or_else(|| matches.values_of_os("search-path"));
82

Minor refactoringsharkdpbefore adoption9d3cb69

lines 83–84why, one step back
83 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 back
85 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 back
88 directories.push(path_buffer);
89 } else {

Improve consistency of lintingDJRHailsbefore adoptionda9af8c

lines 90–93why, one step back
90 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 back
94 }
95 }

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 96why, one step back
96

Minor refactoringsharkdpbefore adoption9d3cb69

lines 97–101why, one step back
97 directories
98 } else {99 vec![current_directory.to_path_buf()]100 };101

Check for no valid search paths to prevent panicDJRHailsbefore adoption28d6a4f

line 102why, one step back
102 // Check if we have no valid search paths.

Minor refactoringsharkdpbefore adoption9d3cb69

line 103why, one step back
103 if search_paths.is_empty() {

Improve consistency of lintingDJRHailsbefore adoptionda9af8c

line 104why, one step back
104 return Err(anyhow!("No valid search paths given."));

Check for no valid search paths to prevent panicDJRHailsbefore adoption28d6a4f

lines 105–106why, one step back
105 }
106

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 107why, one step back
107 if matches.is_present("absolute-path") {

Minor refactoringsharkdpbefore adoption9d3cb69

line 108why, one step back
108 search_paths = search_paths

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 109–112why, one step back
109 .iter()
110 .map(|path_buffer| {111 path_buffer112 .canonicalize()

Rename fshelper to filesystemsharkdpbefore adoptionb415d72

line 113why, one step back
113 .and_then(|pb| filesystem::absolute_path(pb.as_path()))

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 114–121why, one step back
114 .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 back
122 && filesystem::is_dir(Path::new(pattern))

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 123why, one step back
123 {

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 124why, one step back
124 return Err(anyhow!(

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 125–128why, one step back
125 "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 back
129 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 back
130 fd --full-path '{pattern}'",
131 pattern = pattern,132 sep = std::path::MAIN_SEPARATOR,

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 133why, one step back
133 ));

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 134–135why, one step back
134 }
135

Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301

line 136why, one step back
136 let pattern_regex = if matches.is_present("glob") && !pattern.is_empty() {

--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6

line 137why, one step back
137 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;

Implement glob-based searchessharkdpbefore adoptiond5da615

lines 138–140why, one step back
138 glob.regex().to_owned()
139 } else if matches.is_present("fixed-strings") {140 // Treat pattern as literal string if '--fixed-strings' is used

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 141–150why, one step back
141 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));150

Windows: Always enable colors if --color=always is setsharkdpbefore adoption53c338d

line 151why, one step back
151 #[cfg(windows)]

Windows: Check for xterm-256color environment variable as a proxy for color supportsharkdpbefore adoptiona81fef9

lines 152–153why, one step back
152 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 back
154
155 #[cfg(not(windows))]156 let ansi_colors_support = true;157

Print path as raw bytes, allowing invalid UTF-8 filenames to be passed to other processessharkdpbefore adoption6c9e743

line 158why, one step back
158 let interactive_terminal = atty::is(Stream::Stdout);

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 159–161why, one step back
159 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 back
162 _ => 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 back
163 };
164

Remove type annotation.Nathan Moreaubefore adoption588e344

line 165why, one step back
165 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 back
166
167 let ls_colors = if colored_output {168 Some(LsColors::from_env().unwrap_or_default())169 } else {170 None171 };172

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 173–179why, one step back
173 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 back
180

Add testsharkdpbefore adoption4287cdd

line 181why, one step back
181 #[allow(unused)]

Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc

lines 182–191why, one step back
182 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 };191

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

line 192why, one step back
192 let cmd: Vec<&str> = if cfg!(unix) {

Fix some clippy lints, and formatAlexandru Macoveibefore adoption4f43301

lines 193–199why, one step back
193 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 back
200 // Assume ls is GNU ls

Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc

line 201why, one step back
201 gnu_ls("ls")

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

line 202why, one step back
202 } else {

Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894

line 203why, one step back
203 // MacOS, DragonFlyBSD, FreeBSD

Do not show output of 'gls --version'sharkdpbefore adoption0f5500a

line 204why, one step back
204 use std::process::{Command, Stdio};

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

line 205why, one step back
205

Add comment why we prefer glssharkdpbefore adoptiond91100e

line 206why, one step back
206 // 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 back
207 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 back
213
214 if gnu_ls_exists {

Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc

line 215why, one step back
215 gnu_ls("gls")

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

lines 216–217why, one step back
216 } else {
217 let mut cmd = vec![

Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894

line 218why, one step back
218 "ls", // BSD version of ls

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

line 219why, one step back
219 "-l", // long listing format

Fix --list-details on FreeBSDTobias Kortkampbefore adoption4b5e894

line 220why, one step back
220 "-h", // '--human-readable' is not available, '-h' is

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

lines 221–223why, one step back
221 "-d", // '--directory' is not available, but '-d' is
222 ];223

Also add NetBSD and OpenBSDTobias Kortkampbefore adoption04bcd54

lines 224–225why, one step back
224 if !cfg!(any(target_os = "netbsd", target_os = "openbsd")) && colored_output {
225 // -G is not available in NetBSD's and OpenBSD's ls

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

lines 226–231why, one step back
226 cmd.push("-G");
227 }228229 cmd230 }231 }

Windows support (if GNU ls is installed)sharkdpbefore adoption0b7febc

lines 232–246why, one step back
232 } 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 back
247 "'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 back
248 ));
249 }

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

lines 250–251why, one step back
250 } else {
251 return Err(anyhow!(

Add testsharkdpbefore adoption4287cdd

line 252why, one step back
252 "'fd --list-details' is not supported on this platform."

Add MacOS support for -l/--list-detailssharkdpbefore adoption2685728

lines 253–256why, one step back
253 ));
254 };255256 Some(CommandTemplate::new_batch(&cmd).unwrap())

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 257–259why, one step back
257 } else {
258 None259 };

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 260why, one step back
260

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 261–262why, one step back
261 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 back
263 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 back
265 })

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 266–269why, one step back
266 .collect::<Result<Vec<_>>>()?
267 } else {268 vec![]269 };

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 270–276why, one step back
270
271 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 back
277 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 back
281 }
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 back
287 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 back
291 }
292 }293

[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024

lines 294–295why, one step back
294 #[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 back
296 OwnerFilter::from_string(s)?

[ownership] add --owner arg parsing and storageAlexandru Macoveibefore adoption4f9a024

lines 297–300why, one step back
297 } else {
298 None299 };300

Move FdOptions to Optionssharkdpbefore adoption65096a6

line 301why, one step back
301 let config = Options {

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 302–310why, one step back
302 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 back
311 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 back
314 follow_links: matches.is_present("follow"),

Rename `--same-file-system` to `--one-file-system`Simon Engmannbefore adoption94993ca

line 315why, one step back
315 one_file_system: matches.is_present("one-file-system"),

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 316–317why, one step back
316 null_separator: matches.is_present("null_separator"),
317 max_depth: matches

Add --min-depth and --exact-depthsharkdpbefore adoptiond63c63b

line 318why, one step back
318 .value_of("max-depth")

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 319why, one step back
319 .or_else(|| matches.value_of("rg-depth"))

Add --min-depth and --exact-depthsharkdpbefore adoptiond63c63b

lines 320–324why, one step back
320 .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 back
325 .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 back
338 interactive_terminal,

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 339–349why, one step back
339 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 back
350 "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 back
353 _ => 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 back
365 extensions: matches
366 .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 back
376 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 back
387 #[cfg(unix)]
388 owner_constraint,

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 389why, one step back
389 show_filesystem_errors: matches.is_present("show-errors"),

Add path-separator option.Nathan Moreaubefore adoption24e108e

line 390why, one step back
390 path_separator,

Add --max-results=<count> optionsharkdpbefore adoptiond43827f

lines 391–393why, one step back
391 max_results: matches
392 .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 back
394 .filter(|&n| n != 0)

--glob: '*' does not match on path separatorssharkdpbefore adoption47974b6

lines 395–401why, one step back
395 .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 back
402 };
403

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 404why, one step back
404 let re = RegexBuilder::new(&pattern_regex)

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 405–407why, one step back
405 .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 back
408 .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 })?;416

Minor refactoringsharkdpbefore adoption9d3cb69

line 417why, one step back
417 walk::scan(&search_paths, Arc::new(re), Arc::new(config))

Proper error handling in main.rssharkdpbefore adoptionbce9527

lines 418–423why, one step back
418}
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 back
424 process::exit(exit_code.into());
425 }426 Err(err) => {

Proper error handling in main.rssharkdpbefore adoptionbce9527

line 427why, one step back
427 eprintln!("[fd error]: {}", err);

Remove process::exit instancesharkdpbefore adoption4815ee4

line 428why, one step back
428 process::exit(ExitCode::GeneralError.into());

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 429–431why, one step back
429 }
430 }431}