use std::path::PathBuf;
use std::time::Duration;
#[derive(Debug, Clone, Default)]
pub struct OutputConfig {
pub markdown_path: Option<PathBuf>,
pub json_path: Option<PathBuf>,
pub terminal_output: bool,
}
impl OutputConfig {
pub fn builder() -> OutputConfigBuilder {
OutputConfigBuilder::default()
}
pub fn has_output(&self) -> bool {
self.markdown_path.is_some() || self.json_path.is_some() || self.terminal_output
}
}
#[derive(Debug, Clone, Default)]
pub struct OutputConfigBuilder {
config: OutputConfig,
}
impl OutputConfigBuilder {
pub fn markdown(mut self, path: impl Into<PathBuf>) -> Self {
self.config.markdown_path = Some(path.into());
self
}
pub fn json(mut self, path: impl Into<PathBuf>) -> Self {
self.config.json_path = Some(path.into());
self
}
pub fn terminal(mut self, enabled: bool) -> Self {
self.config.terminal_output = enabled;
self
}
pub fn build(self) -> OutputConfig {
self.config
}
}
#[derive(Debug, Clone)]
pub struct OutputResult {
pub destination: String,
pub bytes_written: usize,
pub duration: Duration,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputFormat {
Markdown,
Json,
Terminal,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_output_config_builder() {
let config = OutputConfig::builder()
.markdown("report.md")
.json("report.json")
.terminal(true)
.build();
assert_eq!(config.markdown_path, Some(PathBuf::from("report.md")));
assert_eq!(config.json_path, Some(PathBuf::from("report.json")));
assert!(config.terminal_output);
assert!(config.has_output());
}
#[test]
fn test_output_config_has_output() {
let empty_config = OutputConfig::default();
assert!(!empty_config.has_output());
let with_markdown = OutputConfig::builder().markdown("x.md").build();
assert!(with_markdown.has_output());
let with_terminal = OutputConfig::builder().terminal(true).build();
assert!(with_terminal.has_output());
}
}