Merge pull request #822 from Asha20/pr/opposing-options
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add opposing CLI options
authored by David Peter · committed by GitHub · parents 2570fbd, cdc6a37 · Browse files · 6 files·+139 added−8 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+139 added−8 removed
- tests:+25 added−0 removed
- other:+114 added−8 removed
Provenance
- Commit
a539181- Tree
17ee61a- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
2570fbd- Parent 2
cdc6a37
6 files changed+139 added−8 removed
modified:doc/fd.1+6 added-2 removed
26 unmodified lines27 .SH OPTIONS28 .TP29 .B \-H, \-\-hidden30 Include hidden files and directories in the search results31-(default: hidden files and directories are skipped).31+(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.32 .TP33 .B \-I, \-\-no\-ignore34 Show search results from files and directories that would otherwise be ignored by35 .RS12 unmodified lines48 The global fd ignore file (usually49 .I $HOME/.config/fd/ignore50 )51 .RE52+.IP53+The flag can be overridden with '--ignore'.54 .TP55 .B \-u, \-\-unrestricted56 Alias for '--no-ignore'. Can be repeated; '-uu' is an alias for '--no-ignore --hidden'.57 .TP5 unmodified lines63 and the global gitignore configuration64 .RI ( core.excludesFile65 git setting, which defaults to66 .IR $HOME/.config/git/ignore ).67+The flag can be overridden with '--ignore-vcs'.68 .TP69 .B \-s, \-\-case\-sensitive70 Perform a case-sensitive search. By default, fd uses case-insensitive searches, unless the71 pattern contains an uppercase character (smart case).14 unmodified lines86 performs substring comparison. If you want to match on an exact filename, consider using '\-\-glob'.87 .TP88 .B \-a, \-\-absolute\-path89 Shows the full path starting from the root as opposed to relative paths.90+The flag can be overridden with '--relative-path'.91 .TP92 .B \-l, \-\-list\-details93 Use a detailed listing format like 'ls -l'. This is basically an alias94 for '--exec-batch ls -l' with some additional 'ls' options. This can be used1 unmodified line96 sort order.97 .TP98 .B \-L, \-\-follow99 By default, fd does not descend into symlinked directories. Using this flag, symbolic links are96-also traversed.100+also traversed. The flag can be overridden with '--no-follow'.101 .TP102 .B \-p, \-\-full\-path103 By default, the search pattern is only matched against the filename (or directory name). Using104 this flag, the315 unmodified linesmodified:src/app.rs+55 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+ The flag can be overridden with --no-hidden.",30 ),31 )32 .arg(33+ Arg::with_name("no-hidden")34+ .long("no-hidden")35+ .overrides_with("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+ The flag can be overridden with --ignore.",51 ),52 )53 .arg(54+ Arg::with_name("ignore")55+ .long("ignore")56+ .overrides_with("no-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 .help("Do not respect .gitignore files")68 .long_help(69 "Show search results from files and directories that would otherwise be \50- ignored by '.gitignore' files.",70+ ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs.",71 ),72 )73 .arg(74+ Arg::with_name("ignore-vcs")75+ .long("ignore-vcs")76+ .overrides_with("no-ignore-vcs")77+ .hidden(true)78+ .long_help(79+ "Overrides --no-ignore-vcs.",80+ ),81+ )82+ .arg(83 Arg::with_name("no-ignore-parent")84 .long("no-ignore-parent")85 .overrides_with("no-ignore-parent")86 .hidden_short_help(true)13 unmodified lines100 .arg(101 Arg::with_name("rg-alias-hidden-ignore")102 .short("u")103 .long("unrestricted")104+ .overrides_with_all(&["ignore", "no-hidden"])105 .multiple(true)106 .hidden_short_help(true)107 .help("Alias for '--no-ignore', and '--hidden' when given twice")108 .long_help(65 unmodified lines174 .short("a")175 .overrides_with("absolute-path")176 .help("Show absolute instead of relative paths")177 .long_help(148- "Shows the full path starting from the root as opposed to relative paths.",178+ "Shows the full path starting from the root as opposed to relative paths. \179+ The flag can be overridden with --relative-path.",180 ),181 )182 .arg(183+ Arg::with_name("relative-path")184+ .long("relative-path")185+ .overrides_with("absolute-path")186+ .hidden(true)187+ .long_help(188+ "Overrides --absolute-path.",189+ ),190+ )191+ .arg(192 Arg::with_name("list-details")193 .long("list-details")194 .short("l")195 .conflicts_with("absolute-path")13 unmodified lines209 .overrides_with("follow")210 .help("Follow symbolic links")211 .long_help(212 "By default, fd does not descend into symlinked directories. Using this \173- flag, symbolic links are also traversed.",213+ flag, symbolic links are also traversed. \214+ Flag can be overriden with --no-follow.",215 ),216 )217 .arg(218+ Arg::with_name("no-follow")219+ .long("no-follow")220+ .overrides_with("follow")221+ .hidden(true)222+ .long_help(223+ "Overrides --follow.",224+ ),225+ )226+ .arg(227 Arg::with_name("full-path")228 .long("full-path")229 .short("p")230 .overrides_with("full-path")496 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 1917 unmodified lines1929 1930 te.assert_failure(&["--max-results=a"]);1931 }1932 1933+#[test_case("--hidden", &["--no-hidden"] ; "hidden")]1934+#[test_case("--no-ignore", &["--ignore"] ; "no-ignore")]1935+#[test_case("--no-ignore-vcs", &["--ignore-vcs"] ; "no-ignore-vcs")]1936+#[test_case("--follow", &["--no-follow"] ; "follow")]1937+#[test_case("--absolute-path", &["--relative-path"] ; "absolute-path")]1938+#[test_case("-u", &["--ignore"] ; "u")]1939+#[test_case("-uu", &["--ignore", "--no-hidden"] ; "uu")]1940+fn test_opposing(flag: &str, opposing_flags: &[&str]) {1941+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1942+1943+ let mut flags = vec![flag];1944+ flags.extend_from_slice(opposing_flags);1945+ let out_no_flags = te.assert_success_and_get_output(".", &[]);1946+ let out_opposing_flags = te.assert_success_and_get_output(".", &flags);1947+1948+ assert_eq!(1949+ out_no_flags,1950+ out_opposing_flags,1951+ "{} should override {}",1952+ opposing_flags.join(" "),1953+ flag1954+ );1955+}1956+1957 /// Print error if search pattern starts with a dot and --hidden is not set1958 /// (Unix only, hidden files on Windows work differently)1959 #[test]1960 #[cfg(unix)]10 unmodified linesmodified:Cargo.lock+49 added
179 unmodified lines180 "once_cell",181 "regex",182 "regex-syntax",183 "tempdir",184+ "test-case",185 "users",186 "version_check",187 ]188 207 unmodified lines396 source = "registry+https://github.com/rust-lang/crates.io-index"397 checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"398 399 [[package]]400+name = "proc-macro2"401+version = "1.0.32"402+source = "registry+https://github.com/rust-lang/crates.io-index"403+checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"404+dependencies = [405+ "unicode-xid",406+]407+408+[[package]]409+name = "quote"410+version = "1.0.10"411+source = "registry+https://github.com/rust-lang/crates.io-index"412+checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"413+dependencies = [414+ "proc-macro2",415+]416+417+[[package]]418 name = "rand"419 version = "0.4.6"420 source = "registry+https://github.com/rust-lang/crates.io-index"421 checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"89 unmodified lines511 source = "registry+https://github.com/rust-lang/crates.io-index"512 checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"513 514 [[package]]515+name = "syn"516+version = "1.0.81"517+source = "registry+https://github.com/rust-lang/crates.io-index"518+checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"519+dependencies = [520+ "proc-macro2",521+ "quote",522+ "unicode-xid",523+]524+525+[[package]]526 name = "tempdir"527 version = "0.3.7"528 source = "registry+https://github.com/rust-lang/crates.io-index"529 checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"12 unmodified lines542 "winapi",543 ]544 545 [[package]]546+name = "test-case"547+version = "1.2.1"548+source = "registry+https://github.com/rust-lang/crates.io-index"549+checksum = "c7cad0a06f9a61e94355aa3b3dc92d85ab9c83406722b1ca5e918d4297c12c23"550+dependencies = [551+ "cfg-if",552+ "proc-macro2",553+ "quote",554+ "syn",555+ "version_check",556+]557+558+[[package]]559 name = "textwrap"560 version = "0.11.0"561 source = "registry+https://github.com/rust-lang/crates.io-index"562 checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"27 unmodified lines590 source = "registry+https://github.com/rust-lang/crates.io-index"591 checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"592 593 [[package]]594+name = "unicode-xid"595+version = "0.2.2"596+source = "registry+https://github.com/rust-lang/crates.io-index"597+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"598+599+[[package]]600 name = "users"601 version = "0.11.0"602 source = "registry+https://github.com/rust-lang/crates.io-index"603 checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"64 unmodified linesmodified:Cargo.toml+2 added-1 removed
68 unmodified lines697071727373747576777868 unmodified lines
[dev-dependencies]diff = "0.1"tempdir = "0.3"filetime = "0.2.15"filetime = "0.2"test-case = "1.2"
[profile.release]lto = truecodegen-units = 1modified:CHANGELOG.md+2 added
12 unmodified lines13 - Add new `--no-ignore-parent` flag, see #787 (@will459)14 15 - Add new `--batch-size` flag, see #410 (@devonhollowood)16 17+- Add opposing command-line options, see #595 (@Asha20)18+19 ## Bugfixes20 21 - Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)22 - fd cannot search files under a RAM disk, see #752519 unmodified lines