use s3util_rs::config::TracingConfig;
use crate::cli::BatchRunArgs;
impl BatchRunArgs {
pub fn build_tracing_config(&self) -> Option<TracingConfig> {
let tracing_level = if self.check_format {
Some(
self.verbosity
.log_level()
.map_or(log::Level::Info, |l| l.max(log::Level::Info)),
)
} else {
self.verbosity.log_level()
}?;
Some(TracingConfig {
tracing_level,
json_tracing: self.json_tracing,
aws_sdk_tracing: self.aws_sdk_tracing,
span_events_tracing: self.span_events_tracing,
disable_color_tracing: self.disable_color_tracing,
})
}
}
#[cfg(test)]
mod tests {
use clap::Parser;
use crate::cli::{BatchRunArgs, Cli, Cmd};
fn parse_batch_run_args(args: &[&str]) -> BatchRunArgs {
let cli = Cli::try_parse_from(args).unwrap();
match cli.command {
Some(Cmd::BatchRun(a)) => a,
_ => panic!("expected the batch-run subcommand"),
}
}
#[test]
fn build_tracing_config_without_check_format_uses_plain_verbosity() {
let args = parse_batch_run_args(&["s7cmd", "batch-run", "script.txt"]);
assert!(!args.check_format);
let config = args
.build_tracing_config()
.expect("default verbosity maps to a tracing level");
assert_eq!(config.tracing_level, log::Level::Warn);
}
#[test]
fn build_tracing_config_below_all_levels_returns_none() {
let args = parse_batch_run_args(&["s7cmd", "batch-run", "-qqq", "script.txt"]);
assert!(args.build_tracing_config().is_none());
}
#[test]
fn build_tracing_config_check_format_floors_at_info() {
let args = parse_batch_run_args(&["s7cmd", "batch-run", "--check-format", "script.txt"]);
let config = args
.build_tracing_config()
.expect("check-format always yields a tracing config");
assert_eq!(config.tracing_level, log::Level::Info);
}
}