Use reference in function signatures.

This commit is contained in:
jcamiel 2022-05-18 11:07:09 +02:00 committed by Fabrice Reix
parent da8ae89281
commit af253975b0
3 changed files with 24 additions and 18 deletions

View File

@ -299,7 +299,7 @@ pub fn app(version: &str) -> Command {
) )
} }
pub fn parse_options(matches: ArgMatches) -> Result<CliOptions, CliError> { pub fn parse_options(matches: &ArgMatches) -> Result<CliOptions, CliError> {
let cacert_file = match get_string(&matches, "cacert_file") { let cacert_file = match get_string(&matches, "cacert_file") {
None => None, None => None,
Some(filename) => { Some(filename) => {

View File

@ -86,7 +86,7 @@ fn execute(
filename: &str, filename: &str,
contents: String, contents: String,
current_dir: &Path, current_dir: &Path,
cli_options: CliOptions, cli_options: &CliOptions,
log_verbose: &impl Fn(&str), log_verbose: &impl Fn(&str),
log_error_message: &impl Fn(bool, &str), log_error_message: &impl Fn(bool, &str),
progress: Option<Progress>, progress: Option<Progress>,
@ -123,7 +123,7 @@ fn execute(
if let Some(n) = cli_options.max_redirect { if let Some(n) = cli_options.max_redirect {
log_verbose(format!(" max redirect: {}", n).as_str()); log_verbose(format!(" max redirect: {}", n).as_str());
} }
if let Some(proxy) = cli_options.proxy.clone() { if let Some(proxy) = &cli_options.proxy {
log_verbose(format!(" proxy: {}", proxy).as_str()); log_verbose(format!(" proxy: {}", proxy).as_str());
} }
@ -145,19 +145,19 @@ fn execute(
} }
} }
let cacert_file = cli_options.cacert_file; let cacert_file = cli_options.cacert_file.clone();
let follow_location = cli_options.follow_location; let follow_location = cli_options.follow_location;
let verbose = cli_options.verbose; let verbose = cli_options.verbose;
let insecure = cli_options.insecure; let insecure = cli_options.insecure;
let max_redirect = cli_options.max_redirect; let max_redirect = cli_options.max_redirect;
let proxy = cli_options.proxy; let proxy = cli_options.proxy.clone();
let no_proxy = cli_options.no_proxy; let no_proxy = cli_options.no_proxy.clone();
let cookie_input_file = cli_options.cookie_input_file; let cookie_input_file = cli_options.cookie_input_file.clone();
let timeout = cli_options.timeout; let timeout = cli_options.timeout;
let connect_timeout = cli_options.connect_timeout; let connect_timeout = cli_options.connect_timeout;
let user = cli_options.user; let user = cli_options.user.clone();
let user_agent = cli_options.user_agent; let user_agent = cli_options.user_agent.clone();
let compressed = cli_options.compressed; let compressed = cli_options.compressed;
let context_dir = match cli_options.file_root { let context_dir = match cli_options.file_root {
None => { None => {
@ -199,19 +199,24 @@ fn execute(
} else { } else {
|| false || false
}; };
let fail_fast = cli_options.fail_fast;
let variables = cli_options.variables.clone();
let to_entry = cli_options.to_entry;
let context_dir = context_dir.to_path_buf();
let ignore_asserts = cli_options.ignore_asserts;
let options = RunnerOptions { let options = RunnerOptions {
fail_fast: cli_options.fail_fast, fail_fast,
variables: cli_options.variables, variables,
to_entry: cli_options.to_entry, to_entry,
context_dir: context_dir.to_path_buf(), context_dir,
ignore_asserts: cli_options.ignore_asserts, ignore_asserts,
pre_entry, pre_entry,
post_entry, post_entry,
}; };
let result = runner::run_hurl_file( let result = runner::run_hurl_file(
hurl_file, hurl_file,
&mut client, &mut client,
filename.to_string(), filename,
&options, &options,
&log_verbose, &log_verbose,
&log_error_message, &log_error_message,
@ -261,7 +266,7 @@ fn main() {
let log_verbose = cli::make_logger_verbose(verbose); let log_verbose = cli::make_logger_verbose(verbose);
let color = cli::output_color(matches.clone()); let color = cli::output_color(matches.clone());
let log_error_message = cli::make_logger_error_message(color); let log_error_message = cli::make_logger_error_message(color);
let cli_options = unwrap_or_exit(cli::parse_options(matches.clone()), &log_error_message); let cli_options = unwrap_or_exit(cli::parse_options(&matches), &log_error_message);
let mut filenames = vec![]; let mut filenames = vec![];
if let Some(values) = cli::get_strings(&matches, "INPUT") { if let Some(values) = cli::get_strings(&matches, "INPUT") {
@ -323,7 +328,7 @@ fn main() {
filename, filename,
contents.clone(), contents.clone(),
current_dir, current_dir,
cli_options.clone(), &cli_options,
&log_verbose, &log_verbose,
&log_error_message, &log_error_message,
progress, progress,

View File

@ -80,7 +80,7 @@ use super::entry;
pub fn run( pub fn run(
hurl_file: HurlFile, hurl_file: HurlFile,
http_client: &mut http::Client, http_client: &mut http::Client,
filename: String, filename: &str,
options: &RunnerOptions, options: &RunnerOptions,
log_verbose: &impl Fn(&str), log_verbose: &impl Fn(&str),
log_error_message: &impl Fn(bool, &str), log_error_message: &impl Fn(bool, &str),
@ -143,6 +143,7 @@ pub fn run(
.is_none(); .is_none();
let cookies = http_client.get_cookie_storage(); let cookies = http_client.get_cookie_storage();
let filename = filename.to_string();
HurlResult { HurlResult {
filename, filename,
entries, entries,