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
Provenance
- Commit
37852aa- Tree
0937d66- Author
Vukašin Stepanović <vukasintepanovic@gmail.com>- Committer
Vukašin Stepanović <vukasintepanovic@gmail.com>- Parent
c37592b
6 files changed+148 added−18 removed
modified:src/app.rs+54 added-5 removed
23 unmodified lines24 .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 lines157 .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 lines192 .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 linesmodified:src/main.rs+17 added-13 removed
18 unmodified lines19 use anyhow::{anyhow, Context, Result};20 use atty::Stream;21 use globset::GlobBuilder;22 use lscolors::LsColors;23-use regex::bytes::{RegexBuilder, RegexSetBuilder};23 use normpath::PathExt;24+use regex::bytes::{RegexBuilder, RegexSetBuilder};25 26 use crate::error::print_error;27 use crate::exec::CommandTemplate;28 use crate::exit_codes::ExitCode;86 unmodified lines115 if search_paths.is_empty() {116 return Err(anyhow!("No valid search paths given."));117 }118 119- 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_buffer206 unmodified lines330 331 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 linesmodified:tests/tests.rs+25 added
2 unmodified lines3 use std::fs;4 use std::io::Write;5 use std::path::Path;6 use std::time::{Duration, SystemTime};7+use test_case::test_case;8 9 use normpath::PathExt;10 use regex::escape;11 1776 unmodified lines1788 1789 te.assert_failure(&["--max-results=a"]);1790 }1791 1792+#[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")]1799+fn test_opposing(flag: &str, opposing_flags: &[&str]) {1800+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1801+1802+ 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);1806+1807+ assert_eq!(1808+ out_no_flags,1809+ out_opposing_flags,1810+ "{} should override {}",1811+ opposing_flags.join(" "),1812+ flag1813+ );1814+}1815+1816 /// 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 linesmodified:Cargo.lock+49 added
171 unmodified lines172 "num_cpus",173 "regex",174 "regex-syntax",175 "tempdir",176+ "test-case",177 "users",178 "version_check",179 ]180 172 unmodified lines353 "libc",354 ]355 356 [[package]]357+name = "proc-macro2"358+version = "1.0.28"359+source = "registry+https://github.com/rust-lang/crates.io-index"360+checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"361+dependencies = [362+ "unicode-xid",363+]364+365+[[package]]366+name = "quote"367+version = "1.0.9"368+source = "registry+https://github.com/rust-lang/crates.io-index"369+checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"370+dependencies = [371+ "proc-macro2",372+]373+374+[[package]]375 name = "rand"376 version = "0.4.6"377 source = "registry+https://github.com/rust-lang/crates.io-index"378 checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"95 unmodified lines474 source = "registry+https://github.com/rust-lang/crates.io-index"475 checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"476 477 [[package]]478+name = "syn"479+version = "1.0.74"480+source = "registry+https://github.com/rust-lang/crates.io-index"481+checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"482+dependencies = [483+ "proc-macro2",484+ "quote",485+ "unicode-xid",486+]487+488+[[package]]489 name = "tempdir"490 version = "0.3.7"491 source = "registry+https://github.com/rust-lang/crates.io-index"492 checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"12 unmodified lines505 "winapi",506 ]507 508 [[package]]509+name = "test-case"510+version = "1.2.0"511+source = "registry+https://github.com/rust-lang/crates.io-index"512+checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec"513+dependencies = [514+ "cfg-if 1.0.0",515+ "proc-macro2",516+ "quote",517+ "syn",518+ "version_check",519+]520+521+[[package]]522 name = "textwrap"523 version = "0.11.0"524 source = "registry+https://github.com/rust-lang/crates.io-index"525 checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"17 unmodified lines543 source = "registry+https://github.com/rust-lang/crates.io-index"544 checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"545 546 [[package]]547+name = "unicode-xid"548+version = "0.2.2"549+source = "registry+https://github.com/rust-lang/crates.io-index"550+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"551+552+[[package]]553 name = "users"554 version = "0.11.0"555 source = "registry+https://github.com/rust-lang/crates.io-index"556 checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"64 unmodified linesmodified:Cargo.toml+1 added
67 unmodified lines68697071727374757667 unmodified lines[dev-dependencies]diff = "0.1"tempdir = "0.3"filetime = "0.2.14"test-case = "1.2.0"
[profile.release]lto = truecodegen-units = 1modified:CHANGELOG.md+2 added
1 # Upcoming release2 3 ## Features4 5+- Add opposing command-line options, see #595 (@Asha20)6+7 ## Bugfixes8 9 - Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)10 - fd cannot search files under a RAM disk, see #752515 unmodified lines