Skip to content

Commit

Permalink
Merge pull request #1162 from sharkdp/fix-threads-option
Browse files Browse the repository at this point in the history
Fix --threads/-j option value parsing
  • Loading branch information
sharkdp committed Nov 2, 2022
2 parents cbd11d8 + f15be89 commit 0a7b51a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ pub struct Opts {

/// Set number of threads to use for searching & executing (default: number
/// of available CPU cores)
#[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = 1..)]
#[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = clap::value_parser!(u32).range(1..))]
pub threads: Option<u32>,

/// Milliseconds to buffer before streaming search results to console
Expand Down
8 changes: 8 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,14 @@ fn test_list_details() {
te.assert_success_and_get_output(".", &["--list-details"]);
}

#[test]
fn test_single_and_multithreaded_execution() {
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);

te.assert_output(&["--threads=1", "a.foo"], "a.foo");
te.assert_output(&["--threads=16", "a.foo"], "a.foo");
}

/// Make sure that fd fails if numeric arguments can not be parsed
#[test]
fn test_number_parsing_errors() {
Expand Down

0 comments on commit 0a7b51a

Please sign in to comment.