use crate::processing::filters::ContentFilter;
use regex::Regex;
use std::fmt;
use std::path::PathBuf;
pub use builder::ConfigBuilder;
mod builder;
mod builder_logic;
mod parsing;
pub mod path_resolve;
#[derive(Debug, Clone)]
pub struct DiscoveryConfig {
pub max_size: Option<u128>,
pub recursive: bool,
pub extensions: Option<Vec<String>>,
pub exclude_extensions: Option<Vec<String>>,
pub ignore_patterns: Option<Vec<String>>,
pub exclude_path_regex: Option<Vec<Regex>>,
pub path_regex: Option<Vec<Regex>>,
pub filename_regex: Option<Vec<Regex>>,
pub use_gitignore: bool,
pub skip_lockfiles: bool,
pub process_last: Option<Vec<String>>,
pub only_last: bool,
}
pub struct ProcessingConfig {
pub include_binary: bool,
pub counts: bool,
pub content_filters: Vec<Box<dyn ContentFilter>>,
}
impl fmt::Debug for ProcessingConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ProcessingConfig")
.field("include_binary", &self.include_binary)
.field("counts", &self.counts)
.field("content_filters", &self.content_filters)
.finish()
}
}
#[derive(Debug, Clone, Copy)]
pub struct OutputConfig {
pub filename_only_header: bool,
pub line_numbers: bool,
pub backticks: bool,
pub num_ticks: u8,
pub summary: bool,
pub counts: bool,
}
impl DiscoveryConfig {
#[doc(hidden)]
pub fn default_for_test() -> Self {
Self {
max_size: None,
recursive: true,
extensions: None,
exclude_extensions: None,
ignore_patterns: None,
path_regex: None,
exclude_path_regex: None,
filename_regex: None,
use_gitignore: true,
skip_lockfiles: false,
process_last: None,
only_last: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OutputDestination {
Stdout,
File(PathBuf),
#[cfg(feature = "clipboard")]
Clipboard,
}
pub struct Config {
pub input_path: String,
pub discovery: DiscoveryConfig,
pub processing: ProcessingConfig,
pub output: OutputConfig,
pub output_destination: OutputDestination,
pub dry_run: bool,
#[cfg(feature = "git")]
pub git_branch: Option<String>,
#[cfg(feature = "git")]
pub git_depth: Option<u32>,
#[cfg(feature = "git")]
pub git_cache_path: Option<String>,
}
impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = f.debug_struct("Config");
builder
.field("input_path", &self.input_path)
.field("discovery", &self.discovery)
.field("processing", &self.processing)
.field("output", &self.output)
.field("output_destination", &self.output_destination)
.field("dry_run", &self.dry_run);
#[cfg(feature = "git")]
{
builder
.field("git_branch", &self.git_branch)
.field("git_depth", &self.git_depth)
.field("git_cache_path", &self.git_cache_path);
}
builder.finish()
}
}
impl Config {
#[doc(hidden)]
pub fn new_for_test() -> Self {
Self {
input_path: ".".to_string(),
discovery: DiscoveryConfig {
max_size: None,
recursive: true,
extensions: None,
exclude_extensions: None,
ignore_patterns: None,
path_regex: None,
exclude_path_regex: None,
filename_regex: None,
use_gitignore: true,
skip_lockfiles: false,
process_last: None,
only_last: false,
},
processing: ProcessingConfig {
include_binary: false,
counts: false,
content_filters: Vec::new(),
},
output: OutputConfig {
filename_only_header: false,
line_numbers: false,
backticks: false,
num_ticks: 3,
summary: false,
counts: false,
},
output_destination: OutputDestination::Stdout,
dry_run: false,
#[cfg(feature = "git")]
git_branch: None,
#[cfg(feature = "git")]
git_depth: None,
#[cfg(feature = "git")]
git_cache_path: None,
}
}
}
#[cfg(feature = "git")]
pub use path_resolve::{determine_cache_dir, resolve_input, ResolvedInput};
#[cfg(not(feature = "git"))]
pub use path_resolve::{resolve_input, ResolvedInput};