use clap::Args;
use keyhog_sources::SourceLimits;
#[derive(Args, Clone, Debug, Default)]
pub struct SourceLimitArgs {
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_stdin_bytes: Option<usize>,
#[cfg(feature = "web")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_web_response_bytes: Option<usize>,
#[cfg(feature = "s3")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_s3_object_bytes: Option<usize>,
#[cfg(feature = "gcs")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_gcs_object_bytes: Option<usize>,
#[cfg(feature = "azure")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_azure_blob_bytes: Option<usize>,
#[cfg(any(feature = "s3", feature = "gcs", feature = "azure"))]
#[arg(long, value_name = "N", value_parser = crate::value_parsers::parse_positive_limit_count)]
pub limit_cloud_max_objects: Option<usize>,
#[cfg(feature = "docker")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_docker_tar_entry_bytes: Option<usize>,
#[cfg(feature = "docker")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_docker_image_config_bytes: Option<usize>,
#[cfg(feature = "docker")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_docker_tar_total_bytes: Option<usize>,
#[cfg(feature = "git")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_git_line_bytes: Option<usize>,
#[cfg(feature = "git")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_git_total_bytes: Option<usize>,
#[cfg(feature = "git")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_git_blob_bytes: Option<usize>,
#[cfg(feature = "git")]
#[arg(long, value_name = "N", value_parser = crate::value_parsers::parse_positive_limit_count)]
pub limit_git_chunks: Option<usize>,
#[cfg(any(feature = "github", feature = "gitlab", feature = "bitbucket"))]
#[arg(long, value_name = "N", value_parser = crate::value_parsers::parse_positive_limit_count)]
pub limit_hosted_git_pages: Option<usize>,
#[cfg(feature = "binary")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_binary_read_bytes: Option<usize>,
#[cfg(feature = "binary")]
#[arg(long, value_name = "SIZE", value_parser = crate::value_parsers::parse_byte_size)]
pub limit_binary_decompiled_bytes: Option<usize>,
}
impl SourceLimitArgs {
pub fn to_source_limits(&self) -> SourceLimits {
let mut limits = SourceLimits::default();
if let Some(value) = self.limit_stdin_bytes {
limits.stdin_bytes = value;
}
#[cfg(feature = "web")]
if let Some(value) = self.limit_web_response_bytes {
limits.web_response_bytes = value;
}
#[cfg(feature = "s3")]
if let Some(value) = self.limit_s3_object_bytes {
limits.s3_object_bytes = value as u64;
}
#[cfg(feature = "gcs")]
if let Some(value) = self.limit_gcs_object_bytes {
limits.gcs_object_bytes = value as u64;
}
#[cfg(feature = "azure")]
if let Some(value) = self.limit_azure_blob_bytes {
limits.azure_blob_bytes = value as u64;
}
#[cfg(any(feature = "s3", feature = "gcs", feature = "azure"))]
if let Some(value) = self.limit_cloud_max_objects {
limits.cloud_max_objects = value;
}
#[cfg(feature = "docker")]
if let Some(value) = self.limit_docker_tar_entry_bytes {
limits.docker_tar_entry_bytes = value as u64;
}
#[cfg(feature = "docker")]
if let Some(value) = self.limit_docker_image_config_bytes {
limits.docker_image_config_bytes = value as u64;
}
#[cfg(feature = "docker")]
if let Some(value) = self.limit_docker_tar_total_bytes {
limits.docker_tar_total_bytes = value as u64;
}
#[cfg(feature = "git")]
if let Some(value) = self.limit_git_line_bytes {
limits.git_line_bytes = value;
}
#[cfg(feature = "git")]
if let Some(value) = self.limit_git_total_bytes {
limits.git_total_bytes = value;
}
#[cfg(feature = "git")]
if let Some(value) = self.limit_git_blob_bytes {
limits.git_blob_bytes = value as u64;
}
#[cfg(feature = "git")]
if let Some(value) = self.limit_git_chunks {
limits.git_chunk_count = value;
}
#[cfg(any(feature = "github", feature = "gitlab", feature = "bitbucket"))]
if let Some(value) = self.limit_hosted_git_pages {
limits.hosted_git_pages = value;
}
#[cfg(feature = "binary")]
if let Some(value) = self.limit_binary_read_bytes {
limits.binary_read_bytes = value;
}
#[cfg(feature = "binary")]
if let Some(value) = self.limit_binary_decompiled_bytes {
limits.binary_decompiled_bytes = value as u64;
}
limits
}
}