Add --repeat option.

This commit is contained in:
Jean-Christophe Amiel 2024-06-08 23:30:03 +02:00
parent 1ffd708e5b
commit fe7cba7003
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
10 changed files with 62 additions and 9 deletions

View File

@ -59,6 +59,7 @@ _hurl() {
'--parallel[Run files in parallel (default in test mode)]' \
'--path-as-is[Tell Hurl to not handle sequences of /../ or /./ in the given URL path]' \
'(-x --proxy)'{-x,--proxy}'[Use proxy on given PROTOCOL/HOST/PORT]: :' \
'--repeat[Repeat the input files sequence NUM times, -1 for infinite loop]: :' \
'--report-html[Generate HTML report to DIR]: :' \
'--report-json[Generate JSON report to DIR]: :' \
'--report-junit[Write a JUnit XML report to FILE]: :_files' \

View File

@ -64,6 +64,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock {
[CompletionResult]::new('--parallel', 'parallel', [CompletionResultType]::ParameterName, 'Run files in parallel (default in test mode)')
[CompletionResult]::new('--path-as-is', 'path-as-is', [CompletionResultType]::ParameterName, 'Tell Hurl to not handle sequences of /../ or /./ in the given URL path')
[CompletionResult]::new('--proxy', 'proxy', [CompletionResultType]::ParameterName, 'Use proxy on given PROTOCOL/HOST/PORT')
[CompletionResult]::new('--repeat', 'repeat', [CompletionResultType]::ParameterName, 'Repeat the input files sequence NUM times, -1 for infinite loop')
[CompletionResult]::new('--report-html', 'report-html', [CompletionResultType]::ParameterName, 'Generate HTML report to DIR')
[CompletionResult]::new('--report-json', 'report-json', [CompletionResultType]::ParameterName, 'Generate JSON report to DIR')
[CompletionResult]::new('--report-junit', 'report-junit', [CompletionResultType]::ParameterName, 'Write a JUnit XML report to FILE')

View File

@ -5,7 +5,7 @@ _hurl()
_init_completion || return
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 --jobs --json --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-json --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 --jobs --json --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --repeat --report-html --report-json --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"))
return
fi

View File

@ -42,6 +42,7 @@ complete -c hurl -l output -d 'Write to FILE instead of stdout'
complete -c hurl -l parallel -d 'Run files in parallel (default in test mode)'
complete -c hurl -l path-as-is -d 'Tell Hurl to not handle sequences of /../ or /./ in the given URL path'
complete -c hurl -l proxy -d 'Use proxy on given PROTOCOL/HOST/PORT'
complete -c hurl -l repeat -d 'Repeat the input files sequence NUM times, -1 for infinite loop'
complete -c hurl -l report-html -d 'Generate HTML report to DIR'
complete -c hurl -l report-json -d 'Generate JSON report to DIR'
complete -c hurl -l report-junit -d 'Write a JUnit XML report to FILE'

View File

@ -401,6 +401,13 @@ Tell Hurl to not handle sequences of /../ or /./ in the given URL path. Normally
Use the specified proxy.
### --repeat <NUM> {#repeat}
Repeat the input files sequence NUM times, -1 for infinite loop. Given a.hurl, b.hurl, c.hurl as input, repeat two
times will run a.hurl, b.hurl, c.hurl, a.hurl, b.hurl, c.hurl.
This is a cli-only option.
### --report-html <DIR> {#report-html}
Generate HTML report in DIR.

View File

@ -0,0 +1,9 @@
name: repeat
long: repeat
value: NUM
value_parser: clap::value_parser!(i32).range(-1..)
help: Repeat the input files sequence NUM times, -1 for infinite loop
cli_only: true
---
Repeat the input files sequence NUM times, -1 for infinite loop. Given a.hurl, b.hurl, c.hurl as input, repeat two
times will run a.hurl, b.hurl, c.hurl, a.hurl, b.hurl, c.hurl.

View File

@ -95,6 +95,8 @@ Options:
Tell Hurl to not handle sequences of /../ or /./ in the given URL path
-x, --proxy <[PROTOCOL://]HOST[:PORT]>
Use proxy on given PROTOCOL/HOST/PORT
--repeat <NUM>
Repeat the input files sequence NUM times, -1 for infinite loop
--report-html <DIR>
Generate HTML report to DIR
--report-json <DIR>

View File

@ -395,6 +395,16 @@ pub fn proxy() -> clap::Arg {
.num_args(1)
}
pub fn repeat() -> clap::Arg {
clap::Arg::new("repeat")
.long("repeat")
.value_name("NUM")
.value_parser(clap::value_parser!(i32).range(-1..))
.allow_hyphen_values(true)
.help("Repeat the input files sequence NUM times, -1 for infinite loop")
.num_args(1)
}
pub fn report_html() -> clap::Arg {
clap::Arg::new("report_html")
.long("report-html")

View File

@ -27,7 +27,7 @@ use hurl::runner::{Input, Value};
use hurl_core::ast::Retry;
use super::variables::{parse as parse_variable, parse_value};
use super::CliOptionsError;
use super::{CliOptionsError, Repeat};
use crate::cli::options::{ErrorFormat, HttpVersion, IpResolve, Output};
use crate::cli::OutputType;
@ -334,6 +334,14 @@ pub fn proxy(arg_matches: &ArgMatches) -> Option<String> {
get::<String>(arg_matches, "proxy")
}
pub fn repeat(arg_matches: &ArgMatches) -> Option<Repeat> {
match get::<i32>(arg_matches, "repeat") {
Some(-1) => Some(Repeat::Forever),
Some(n) => Some(Repeat::Count(n as usize)),
None => None,
}
}
pub fn resolves(arg_matches: &ArgMatches) -> Vec<String> {
get_strings(arg_matches, "resolve").unwrap_or_default()
}

View File

@ -80,6 +80,7 @@ pub struct CliOptions {
pub path_as_is: bool,
pub progress_bar: bool,
pub proxy: Option<String>,
pub repeat: Option<Repeat>,
pub resolves: Vec<String>,
pub retry: Retry,
pub retry_interval: Duration,
@ -96,12 +97,23 @@ pub struct CliOptions {
pub very_verbose: bool,
}
/// Error format: long or rich.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ErrorFormat {
Short,
Long,
}
impl From<ErrorFormat> for hurl::util::logger::ErrorFormat {
fn from(value: ErrorFormat) -> Self {
match value {
ErrorFormat::Short => hurl::util::logger::ErrorFormat::Short,
ErrorFormat::Long => hurl::util::logger::ErrorFormat::Long,
}
}
}
/// Requested HTTP version.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum HttpVersion {
V10,
@ -121,6 +133,7 @@ impl From<HttpVersion> for RequestedHttpVersion {
}
}
/// IP protocol used.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum IpResolve {
IpV4,
@ -136,13 +149,11 @@ impl From<IpResolve> for http::IpResolve {
}
}
impl From<ErrorFormat> for hurl::util::logger::ErrorFormat {
fn from(value: ErrorFormat) -> Self {
match value {
ErrorFormat::Short => hurl::util::logger::ErrorFormat::Short,
ErrorFormat::Long => hurl::util::logger::ErrorFormat::Long,
}
}
/// Repeat mode: infinite of finite.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Repeat {
Count(usize),
Forever,
}
fn get_version() -> String {
@ -206,6 +217,7 @@ pub fn parse() -> Result<CliOptions, CliOptionsError> {
.arg(commands::parallel())
.arg(commands::path_as_is())
.arg(commands::proxy())
.arg(commands::repeat())
.arg(commands::report_html())
.arg(commands::report_json())
.arg(commands::report_junit())
@ -281,6 +293,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
let proxy = matches::proxy(arg_matches);
let output = matches::output(arg_matches);
let output_type = matches::output_type(arg_matches);
let repeat = matches::repeat(arg_matches);
let resolves = matches::resolves(arg_matches);
let retry = matches::retry(arg_matches);
let retry_interval = matches::retry_interval(arg_matches);
@ -336,6 +349,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
proxy,
output,
output_type,
repeat,
resolves,
retry,
retry_interval,