Skip to content
Myr

Add 5 opposing CLI options

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Those are: - `--no-hidden`, which overrides `--hidden` - `--ignore`, which overrides `--no-ignore` - `--ignore-vcs`, which overrides `--no-ignore-vcs` - `--no-follow`, which overrides `--follow` - `--relative-path`, which overrides `--absolute-path`

authored by Vukašin Stepanović · committed by Vukašin Stepanović · parent c37592b · Browse files · 6 files+148 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+148 added−18 removed

  • tests:+25 added−0 removed
  • other:+123 added−18 removed

6 files+148 added−18 removed

modified:src/app.rs+54 added-5 removed
23 unmodified lines
24 .help("Search hidden files and directories")25 .long_help(26 "Include hidden directories and files in the search results (default: \27 hidden files and directories are skipped). Files and directories are \28 considered to be hidden if their name starts with a `.` sign (dot).",28 considered to be hidden if their name starts with a `.` sign (dot). \29 Flag can be overridden with --no-hidden.",30 ),31 )32 .arg(33 Arg::with_name("no-hidden")34 .long("no-hidden")35 .overrides_with("no-hidden")36 .hidden(true)37 .long_help(38 "Overrides --hidden.",39 ),40 )41 .arg(42 Arg::with_name("no-ignore")43 .long("no-ignore")44 .short("I")45 .overrides_with("no-ignore")46 .help("Do not respect .(git|fd)ignore files")47 .long_help(48 "Show search results from files and directories that would otherwise be \39 ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file.",49 ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file. \50 Flag can be overridden with --ignore.",51 ),52 )53 .arg(54 Arg::with_name("ignore")55 .long("ignore")56 .overrides_with("ignore")57 .hidden(true)58 .long_help(59 "Overrides --no-ignore.",60 ),61 )62 .arg(63 Arg::with_name("no-ignore-vcs")64 .long("no-ignore-vcs")65 .overrides_with("no-ignore-vcs")66 .hidden_short_help(true)67 .long_help(68 "Show search results from files and directories that would otherwise be \49 ignored by '.gitignore' files.",69 ignored by '.gitignore' files. Flag can be overridden with --ignore-vcs.",70 ),71 )72 .arg(73 Arg::with_name("ignore-vcs")74 .long("ignore-vcs")75 .overrides_with("ignore-vcs")76 .hidden(true)77 .long_help(78 "Overrides --no-ignore-vcs.",79 ),80 )81 .arg(82 Arg::with_name("no-global-ignore-file")83 .long("no-global-ignore-file")84 .hidden(true)85 .long_help("Do not respect the global ignore file."),
71 unmodified lines
157 .short("a")158 .overrides_with("absolute-path")159 .help("Show absolute instead of relative paths")160 .long_help(132 "Shows the full path starting from the root as opposed to relative paths.",161 "Shows the full path starting from the root as opposed to relative paths. \162 Flag can be overridden with --relative-path.",163 ),164 )165 .arg(166 Arg::with_name("relative-path")167 .long("relative-path")168 .overrides_with("relative-path")169 .hidden(true)170 .long_help(171 "Overrides --absolute-path.",172 ),173 )174 .arg(175 Arg::with_name("list-details")176 .long("list-details")177 .short("l")178 .conflicts_with("absolute-path")
13 unmodified lines
192 .overrides_with("follow")193 .help("Follow symbolic links")194 .long_help(195 "By default, fd does not descend into symlinked directories. Using this \157 flag, symbolic links are also traversed.",196 flag, symbolic links are also traversed. \197 Flag can be overriden with --no-follow.",198 ),199 )200 .arg(201 Arg::with_name("no-follow")202 .long("no-follow")203 .overrides_with("no-follow")204 .hidden(true)205 .long_help(206 "Overrides --follow.",207 ),208 )209 .arg(210 Arg::with_name("full-path")211 .long("full-path")212 .short("p")213 .overrides_with("full-path")
451 unmodified lines
modified:src/main.rs+17 added-13 removed
18 unmodified lines
19use anyhow::{anyhow, Context, Result};20use atty::Stream;21use globset::GlobBuilder;22use lscolors::LsColors;23use regex::bytes::{RegexBuilder, RegexSetBuilder};23use normpath::PathExt;24use regex::bytes::{RegexBuilder, RegexSetBuilder};2526use crate::error::print_error;27use crate::exec::CommandTemplate;28use crate::exit_codes::ExitCode;
86 unmodified lines
115 if search_paths.is_empty() {116 return Err(anyhow!("No valid search paths given."));117 }118119 if matches.is_present("absolute-path") {119 if matches.is_present("absolute-path") && !matches.is_present("relative-path") {120 search_paths = search_paths121 .iter()122 .map(|path_buffer| {123 path_buffer
206 unmodified lines
330331 let config = Options {332 case_sensitive,333 search_full_path: matches.is_present("full-path"),334 ignore_hidden: !(matches.is_present("hidden")335 || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),336 read_fdignore: !(matches.is_present("no-ignore")337 || matches.is_present("rg-alias-hidden-ignore")),338 read_vcsignore: !(matches.is_present("no-ignore")339 || matches.is_present("rg-alias-hidden-ignore")340 || matches.is_present("no-ignore-vcs")),341 read_global_ignore: !(matches.is_present("no-ignore")342 || matches.is_present("rg-alias-hidden-ignore")343 || matches.is_present("no-global-ignore-file")),344 follow_links: matches.is_present("follow"),334 ignore_hidden: matches.is_present("no-hidden")335 || !(matches.is_present("hidden")336 || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),337 read_fdignore: matches.is_present("ignore")338 || !(matches.is_present("no-ignore") || matches.is_present("rg-alias-hidden-ignore")),339 read_vcsignore: matches.is_present("ignore") || matches.is_present("ignore-vcs") || {340 !(matches.is_present("no-ignore")341 || matches.is_present("rg-alias-hidden-ignore")342 || matches.is_present("no-ignore-vcs"))343 },344 read_global_ignore: matches.is_present("ignore")345 || !(matches.is_present("no-ignore")346 || matches.is_present("rg-alias-hidden-ignore")347 || matches.is_present("no-global-ignore-file")),348 follow_links: matches.is_present("follow") && !matches.is_present("no-follow"),349 one_file_system: matches.is_present("one-file-system"),350 null_separator: matches.is_present("null_separator"),351 max_depth: matches352 .value_of("max-depth")
143 unmodified lines
modified:tests/tests.rs+25 added
2 unmodified lines
3use std::fs;4use std::io::Write;5use std::path::Path;6use std::time::{Duration, SystemTime};7use test_case::test_case;89use normpath::PathExt;10use regex::escape;11
1776 unmodified lines
17881789 te.assert_failure(&["--max-results=a"]);1790}17911792#[test_case("--hidden", &["--no-hidden"] ; "hidden")]1793#[test_case("--no-ignore", &["--ignore"] ; "no-ignore")]1794#[test_case("--no-ignore-vcs", &["--ignore-vcs"] ; "no-ignore-vcs")]1795#[test_case("--follow", &["--no-follow"] ; "follow")]1796#[test_case("--absolute-path", &["--relative-path"] ; "absolute-path")]1797#[test_case("-u", &["--ignore"] ; "u")]1798#[test_case("-uu", &["--ignore", "--no-hidden"] ; "uu")]1799fn test_opposing(flag: &str, opposing_flags: &[&str]) {1800 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);18011802 let mut flags = vec![flag];1803 flags.extend_from_slice(opposing_flags);1804 let out_no_flags = te.assert_success_and_get_output(".", &[]);1805 let out_opposing_flags = te.assert_success_and_get_output(".", &flags);18061807 assert_eq!(1808 out_no_flags,1809 out_opposing_flags,1810 "{} should override {}",1811 opposing_flags.join(" "),1812 flag1813 );1814}18151816/// Print error if search pattern starts with a dot and --hidden is not set1817/// (Unix only, hidden files on Windows work differently)1818#[test]1819#[cfg(unix)]
10 unmodified lines
modified:Cargo.lock+49 added
171 unmodified lines
172 "num_cpus",173 "regex",174 "regex-syntax",175 "tempdir",176 "test-case",177 "users",178 "version_check",179]180
172 unmodified lines
353 "libc",354]355356[[package]]357name = "proc-macro2"358version = "1.0.28"359source = "registry+https://github.com/rust-lang/crates.io-index"360checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"361dependencies = [362 "unicode-xid",363]364365[[package]]366name = "quote"367version = "1.0.9"368source = "registry+https://github.com/rust-lang/crates.io-index"369checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"370dependencies = [371 "proc-macro2",372]373374[[package]]375name = "rand"376version = "0.4.6"377source = "registry+https://github.com/rust-lang/crates.io-index"378checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
95 unmodified lines
474source = "registry+https://github.com/rust-lang/crates.io-index"475checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"476477[[package]]478name = "syn"479version = "1.0.74"480source = "registry+https://github.com/rust-lang/crates.io-index"481checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"482dependencies = [483 "proc-macro2",484 "quote",485 "unicode-xid",486]487488[[package]]489name = "tempdir"490version = "0.3.7"491source = "registry+https://github.com/rust-lang/crates.io-index"492checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
12 unmodified lines
505 "winapi",506]507508[[package]]509name = "test-case"510version = "1.2.0"511source = "registry+https://github.com/rust-lang/crates.io-index"512checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec"513dependencies = [514 "cfg-if 1.0.0",515 "proc-macro2",516 "quote",517 "syn",518 "version_check",519]520521[[package]]522name = "textwrap"523version = "0.11.0"524source = "registry+https://github.com/rust-lang/crates.io-index"525checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
17 unmodified lines
543source = "registry+https://github.com/rust-lang/crates.io-index"544checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"545546[[package]]547name = "unicode-xid"548version = "0.2.2"549source = "registry+https://github.com/rust-lang/crates.io-index"550checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"551552[[package]]553name = "users"554version = "0.11.0"555source = "registry+https://github.com/rust-lang/crates.io-index"556checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
64 unmodified lines
modified:Cargo.toml+1 added
modified:CHANGELOG.md+2 added
1# Upcoming release23## Features45- Add opposing command-line options, see #595 (@Asha20)67## Bugfixes89- Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)10- fd cannot search files under a RAM disk, see #752
515 unmodified lines