Rename option to strip_cwd_prefix, rename CLI option

This commit is contained in:
David Peter 2021-11-26 17:46:04 +01:00
parent 359c0269ba
commit 4d7e34ad59
5 changed files with 13 additions and 13 deletions

View file

@ -617,10 +617,10 @@ pub fn build_app() -> App<'static, 'static> {
), ),
) )
.arg( .arg(
Arg::with_name("strip-prefix") Arg::with_name("strip-cwd-prefix")
.long("strip-prefix") .long("strip-cwd-prefix")
.short("P")
.conflicts_with_all(&["path", "search-path"]) .conflicts_with_all(&["path", "search-path"])
.hidden_short_help(true)
.help("When no search path is provided and output is non-tty, strip './' prefix from results") .help("When no search path is provided and output is non-tty, strip './' prefix from results")
.long_help( .long_help(
"By default, relative results are prefixed with './' when output to non-ttys. \ "By default, relative results are prefixed with './' when output to non-ttys. \

View file

@ -110,6 +110,6 @@ pub struct Config {
/// The maximum number of search results /// The maximum number of search results
pub max_results: Option<usize>, pub max_results: Option<usize>,
/// Whether to prefix each relative path with "./" /// Whether or not to strip the './' prefix for search results
pub no_strip: bool, pub strip_cwd_prefix: bool,
} }

View file

@ -375,9 +375,9 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
None None
} }
}), }),
no_strip: matches.is_present("path") strip_cwd_prefix: (!matches.is_present("path")
|| matches.is_present("search-path") && !matches.is_present("search-path")
|| (!interactive_terminal && !matches.is_present("strip-prefix")), && (interactive_terminal || matches.is_present("strip-cwd-prefix"))),
}) })
} }

View file

@ -22,10 +22,10 @@ pub fn print_entry(
config: &Config, config: &Config,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
) { ) {
let path = if config.no_strip { let path = if config.strip_cwd_prefix {
entry
} else {
strip_current_dir(entry) strip_current_dir(entry)
} else {
entry
}; };
let r = if let Some(ref ls_colors) = config.ls_colors { let r = if let Some(ref ls_colors) = config.ls_colors {

View file

@ -1925,11 +1925,11 @@ fn test_error_if_hidden_not_set_and_pattern_starts_with_dot() {
} }
#[test] #[test]
fn test_no_strip() { fn test_strip_cwd_prefix() {
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES); let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
te.assert_output( te.assert_output(
&["-P", "."], &["--strip-cwd-prefix", "."],
"a.foo "a.foo
e1 e2 e1 e2
one one