Rename workers option

This commit is contained in:
jcamiel 2024-03-31 13:57:20 +02:00
parent e65c66b40b
commit bf472937f9
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
12 changed files with 32 additions and 33 deletions

View File

@ -47,7 +47,6 @@ _hurl() {
'--json[Output each Hurl file result to JSON]' \ '--json[Output each Hurl file result to JSON]' \
'--max-redirs[Maximum number of redirects allowed, -1 for unlimited redirects]: :' \ '--max-redirs[Maximum number of redirects allowed, -1 for unlimited redirects]: :' \
'(-m --max-time)'{-m,--max-time}'[Maximum time allowed for the transfer]: :' \ '(-m --max-time)'{-m,--max-time}'[Maximum time allowed for the transfer]: :' \
'--max-workers[(Experimental) Maximum number of parallel execution]: :' \
'(-n --netrc)'{-n,--netrc}'[Must read .netrc for username and password]' \ '(-n --netrc)'{-n,--netrc}'[Must read .netrc for username and password]' \
'--netrc-file[Specify FILE for .netrc]: :_files' \ '--netrc-file[Specify FILE for .netrc]: :_files' \
'--netrc-optional[Use either .netrc or the URL]' \ '--netrc-optional[Use either .netrc or the URL]' \
@ -74,6 +73,7 @@ _hurl() {
'*--variables-file[Define a properties file in which you define your variables]: :_files' \ '*--variables-file[Define a properties file in which you define your variables]: :_files' \
'(-v --verbose)'{-v,--verbose}'[Turn on verbose]' \ '(-v --verbose)'{-v,--verbose}'[Turn on verbose]' \
'--very-verbose[Turn on verbose output, including HTTP response and libcurl logs]' \ '--very-verbose[Turn on verbose output, including HTTP response and libcurl logs]' \
'--workers[(Experimental) Maximum number of parallel execution]: :' \
'--help[Print help]' \ '--help[Print help]' \
'--version[Print version]' \ '--version[Print version]' \
'*:file:_files' \ '*:file:_files' \

View File

@ -52,7 +52,6 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock {
[CompletionResult]::new('--json', 'json', [CompletionResultType]::ParameterName, 'Output each Hurl file result to JSON') [CompletionResult]::new('--json', 'json', [CompletionResultType]::ParameterName, 'Output each Hurl file result to JSON')
[CompletionResult]::new('--max-redirs', 'max-redirs', [CompletionResultType]::ParameterName, 'Maximum number of redirects allowed, -1 for unlimited redirects') [CompletionResult]::new('--max-redirs', 'max-redirs', [CompletionResultType]::ParameterName, 'Maximum number of redirects allowed, -1 for unlimited redirects')
[CompletionResult]::new('--max-time', 'max-time', [CompletionResultType]::ParameterName, 'Maximum time allowed for the transfer') [CompletionResult]::new('--max-time', 'max-time', [CompletionResultType]::ParameterName, 'Maximum time allowed for the transfer')
[CompletionResult]::new('--max-workers', 'max-workers', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel execution')
[CompletionResult]::new('--netrc', 'netrc', [CompletionResultType]::ParameterName, 'Must read .netrc for username and password') [CompletionResult]::new('--netrc', 'netrc', [CompletionResultType]::ParameterName, 'Must read .netrc for username and password')
[CompletionResult]::new('--netrc-file', 'netrc-file', [CompletionResultType]::ParameterName, 'Specify FILE for .netrc') [CompletionResult]::new('--netrc-file', 'netrc-file', [CompletionResultType]::ParameterName, 'Specify FILE for .netrc')
[CompletionResult]::new('--netrc-optional', 'netrc-optional', [CompletionResultType]::ParameterName, 'Use either .netrc or the URL') [CompletionResult]::new('--netrc-optional', 'netrc-optional', [CompletionResultType]::ParameterName, 'Use either .netrc or the URL')
@ -79,6 +78,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock {
[CompletionResult]::new('--variables-file', 'variables-file', [CompletionResultType]::ParameterName, 'Define a properties file in which you define your variables') [CompletionResult]::new('--variables-file', 'variables-file', [CompletionResultType]::ParameterName, 'Define a properties file in which you define your variables')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Turn on verbose') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Turn on verbose')
[CompletionResult]::new('--very-verbose', 'very-verbose', [CompletionResultType]::ParameterName, 'Turn on verbose output, including HTTP response and libcurl logs') [CompletionResult]::new('--very-verbose', 'very-verbose', [CompletionResultType]::ParameterName, 'Turn on verbose output, including HTTP response and libcurl logs')
[CompletionResult]::new('--workers', 'workers', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel execution')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break break

View File

@ -5,7 +5,7 @@ _hurl()
_init_completion || return _init_completion || return
if [[ $cur == -* ]]; then if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --json --max-redirs --max-time --max-workers --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur")) COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --json --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --workers --help --version' -- "$cur"))
return return
fi fi

View File

@ -30,7 +30,6 @@ complete -c hurl -l ipv6 -d 'Tell Hurl to use IPv6 addresses only when resolving
complete -c hurl -l json -d 'Output each Hurl file result to JSON' complete -c hurl -l json -d 'Output each Hurl file result to JSON'
complete -c hurl -l max-redirs -d 'Maximum number of redirects allowed, -1 for unlimited redirects' complete -c hurl -l max-redirs -d 'Maximum number of redirects allowed, -1 for unlimited redirects'
complete -c hurl -l max-time -d 'Maximum time allowed for the transfer' complete -c hurl -l max-time -d 'Maximum time allowed for the transfer'
complete -c hurl -l max-workers -d '(Experimental) Maximum number of parallel execution'
complete -c hurl -l netrc -d 'Must read .netrc for username and password' complete -c hurl -l netrc -d 'Must read .netrc for username and password'
complete -c hurl -l netrc-file -d 'Specify FILE for .netrc' complete -c hurl -l netrc-file -d 'Specify FILE for .netrc'
complete -c hurl -l netrc-optional -d 'Use either .netrc or the URL' complete -c hurl -l netrc-optional -d 'Use either .netrc or the URL'
@ -57,6 +56,7 @@ complete -c hurl -l variable -d 'Define a variable'
complete -c hurl -l variables-file -d 'Define a properties file in which you define your variables' complete -c hurl -l variables-file -d 'Define a properties file in which you define your variables'
complete -c hurl -l verbose -d 'Turn on verbose' complete -c hurl -l verbose -d 'Turn on verbose'
complete -c hurl -l very-verbose -d 'Turn on verbose output, including HTTP response and libcurl logs' complete -c hurl -l very-verbose -d 'Turn on verbose output, including HTTP response and libcurl logs'
complete -c hurl -l workers -d '(Experimental) Maximum number of parallel execution'
complete -c hurl -l help -d 'Print help' complete -c hurl -l help -d 'Print help'
complete -c hurl -l version -d 'Print version' complete -c hurl -l version -d 'Print version'

View File

@ -1,12 +1,12 @@
name: max_workers name: workers
long: max-workers long: workers
value: NUM value: NUM
value_default: 6
value_parser: clap::value_parser!(u32).range(1..) value_parser: clap::value_parser!(u32).range(1..)
help: (Experimental) Maximum number of parallel execution help: (Experimental) Maximum number of parallel execution
cli_only: true cli_only: true
experimental: true experimental: true
--- ---
(Experimental) Maximum number of parallel execution in parallel mode. (Experimental) Maximum number of parallel execution in parallel mode. Default value corresponds (in most cases) to the
current amount of CPUs.
See also [`--parallel`](#parallel). See also [`--parallel`](#parallel).

View File

@ -1,7 +1,7 @@
Set-StrictMode -Version latest Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
hurl --parallel --max-workers 1 ` hurl --parallel --workers 1 `
tests_ok/parallel_a.hurl ` tests_ok/parallel_a.hurl `
tests_ok/parallel_b.hurl ` tests_ok/parallel_b.hurl `
tests_ok/parallel_c.hurl ` tests_ok/parallel_c.hurl `

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -Eeuo pipefail set -Eeuo pipefail
hurl --parallel --max-workers 1 \ hurl --parallel --workers 1 \
tests_ok/parallel_a.hurl \ tests_ok/parallel_a.hurl \
tests_ok/parallel_b.hurl \ tests_ok/parallel_b.hurl \
tests_ok/parallel_c.hurl \ tests_ok/parallel_c.hurl \

View File

@ -294,17 +294,6 @@ pub fn max_time() -> clap::Arg {
.num_args(1) .num_args(1)
} }
pub fn max_workers() -> clap::Arg {
clap::Arg::new("max_workers")
.long("max-workers")
.value_name("NUM")
.default_value("6")
.value_parser(clap::value_parser!(u32).range(1..))
.help("(Experimental) Maximum number of parallel execution")
.num_args(1)
.hide(true)
}
pub fn netrc() -> clap::Arg { pub fn netrc() -> clap::Arg {
clap::Arg::new("netrc") clap::Arg::new("netrc")
.long("netrc") .long("netrc")
@ -525,3 +514,13 @@ pub fn very_verbose() -> clap::Arg {
.help("Turn on verbose output, including HTTP response and libcurl logs") .help("Turn on verbose output, including HTTP response and libcurl logs")
.action(clap::ArgAction::SetTrue) .action(clap::ArgAction::SetTrue)
} }
pub fn workers() -> clap::Arg {
clap::Arg::new("workers")
.long("workers")
.value_name("NUM")
.value_parser(clap::value_parser!(u32).range(1..))
.help("(Experimental) Maximum number of parallel execution")
.num_args(1)
.hide(true)
}

View File

@ -250,8 +250,8 @@ pub fn max_redirect(arg_matches: &ArgMatches) -> Option<usize> {
} }
} }
pub fn max_workers(arg_matches: &ArgMatches) -> Option<usize> { pub fn workers(arg_matches: &ArgMatches) -> Option<usize> {
get::<u32>(arg_matches, "max_workers").map(|m| m as usize) get::<u32>(arg_matches, "workers").map(|m| m as usize)
} }
pub fn netrc(arg_matches: &ArgMatches) -> bool { pub fn netrc(arg_matches: &ArgMatches) -> bool {

View File

@ -67,7 +67,6 @@ pub struct CliOptions {
pub ip_resolve: Option<IpResolve>, pub ip_resolve: Option<IpResolve>,
pub junit_file: Option<PathBuf>, pub junit_file: Option<PathBuf>,
pub max_redirect: Option<usize>, pub max_redirect: Option<usize>,
pub max_workers: Option<usize>,
pub netrc: bool, pub netrc: bool,
pub netrc_file: Option<String>, pub netrc_file: Option<String>,
pub netrc_optional: bool, pub netrc_optional: bool,
@ -92,6 +91,7 @@ pub struct CliOptions {
pub variables: HashMap<String, Value>, pub variables: HashMap<String, Value>,
pub verbose: bool, pub verbose: bool,
pub very_verbose: bool, pub very_verbose: bool,
pub workers: Option<usize>,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -192,7 +192,6 @@ pub fn parse() -> Result<CliOptions, CliOptionsError> {
.arg(commands::json()) .arg(commands::json())
.arg(commands::max_redirects()) .arg(commands::max_redirects())
.arg(commands::max_time()) .arg(commands::max_time())
.arg(commands::max_workers())
.arg(commands::netrc()) .arg(commands::netrc())
.arg(commands::netrc_file()) .arg(commands::netrc_file())
.arg(commands::netrc_optional()) .arg(commands::netrc_optional())
@ -218,7 +217,8 @@ pub fn parse() -> Result<CliOptions, CliOptionsError> {
.arg(commands::variable()) .arg(commands::variable())
.arg(commands::variables_file()) .arg(commands::variables_file())
.arg(commands::verbose()) .arg(commands::verbose())
.arg(commands::very_verbose()); .arg(commands::very_verbose())
.arg(commands::workers());
let arg_matches = command.try_get_matches_from_mut(env::args_os())?; let arg_matches = command.try_get_matches_from_mut(env::args_os())?;
let opts = parse_matches(&arg_matches)?; let opts = parse_matches(&arg_matches)?;
@ -265,7 +265,6 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
let ip_resolve = matches::ip_resolve(arg_matches); let ip_resolve = matches::ip_resolve(arg_matches);
let junit_file = matches::junit_file(arg_matches); let junit_file = matches::junit_file(arg_matches);
let max_redirect = matches::max_redirect(arg_matches); let max_redirect = matches::max_redirect(arg_matches);
let max_workers = matches::max_workers(arg_matches);
let netrc = matches::netrc(arg_matches); let netrc = matches::netrc(arg_matches);
let netrc_file = matches::netrc_file(arg_matches)?; let netrc_file = matches::netrc_file(arg_matches)?;
let netrc_optional = matches::netrc_optional(arg_matches); let netrc_optional = matches::netrc_optional(arg_matches);
@ -290,6 +289,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
let variables = matches::variables(arg_matches)?; let variables = matches::variables(arg_matches)?;
let verbose = matches::verbose(arg_matches); let verbose = matches::verbose(arg_matches);
let very_verbose = matches::very_verbose(arg_matches); let very_verbose = matches::very_verbose(arg_matches);
let workers = matches::workers(arg_matches);
Ok(CliOptions { Ok(CliOptions {
aws_sigv4, aws_sigv4,
cacert_file, cacert_file,
@ -318,7 +318,6 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
ip_resolve, ip_resolve,
junit_file, junit_file,
max_redirect, max_redirect,
max_workers,
netrc, netrc,
netrc_file, netrc_file,
netrc_optional, netrc_optional,
@ -343,6 +342,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
variables, variables,
verbose, verbose,
very_verbose, very_verbose,
workers,
}) })
} }

View File

@ -82,10 +82,10 @@ fn main() {
EXIT_ERROR_UNDEFINED, EXIT_ERROR_UNDEFINED,
&base_logger, &base_logger,
); );
let max_workers = opts.max_workers.unwrap_or(available.get()); let workers = opts.workers.unwrap_or(available.get());
base_logger.debug(&format!("Parallel run using {max_workers} workers")); base_logger.debug(&format!("Parallel run using {workers} workers"));
run::run_par(&opts.input_files, current_dir, &opts, max_workers) run::run_par(&opts.input_files, current_dir, &opts, workers)
} else { } else {
run::run_seq(&opts.input_files, current_dir, &opts) run::run_seq(&opts.input_files, current_dir, &opts)
}; };

View File

@ -125,9 +125,9 @@ pub fn run_par(
files: &[Input], files: &[Input],
current_dir: &Path, current_dir: &Path,
options: &CliOptions, options: &CliOptions,
max_workers: usize, workers: usize,
) -> Result<Vec<HurlRun>, CliError> { ) -> Result<Vec<HurlRun>, CliError> {
let workers_count = min(files.len(), max_workers); let workers_count = min(files.len(), workers);
let variables = &options.variables; let variables = &options.variables;
let output_type = options let output_type = options
.output_type .output_type