use serde::{Deserialize, Serialize};
use super::{KnownFields, default_true};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct StandardConfig {
#[serde(default)]
pub command: String,
#[serde(default)]
pub formats: Vec<String>,
#[serde(default)]
pub args: Vec<String>,
#[serde(default)]
pub dep_inputs: Vec<String>,
#[serde(default)]
pub dep_auto: Vec<String>,
#[serde(default)]
pub output_dir: String,
#[serde(default)]
pub required_tools: Vec<String>,
#[serde(default = "default_true")]
pub batch: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_jobs: Option<usize>,
#[serde(default = "default_true")]
pub enabled: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_dirs: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_extensions: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_exclude_dirs: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_exclude_files: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_exclude_paths: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub src_files: Option<Vec<String>>,
}
impl Default for StandardConfig {
fn default() -> Self {
Self {
command: String::new(),
formats: Vec::new(),
args: Vec::new(),
dep_inputs: Vec::new(),
dep_auto: Vec::new(),
output_dir: String::new(),
required_tools: Vec::new(),
batch: true,
max_jobs: None,
enabled: true,
src_dirs: None,
src_extensions: None,
src_exclude_dirs: None,
src_exclude_files: None,
src_exclude_paths: None,
src_files: None,
}
}
}
impl StandardConfig {
pub(crate) fn src_dirs(&self) -> &[String] {
self.src_dirs
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn src_extensions(&self) -> &[String] {
self.src_extensions
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn src_exclude_dirs(&self) -> &[String] {
self.src_exclude_dirs
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn src_exclude_files(&self) -> &[String] {
self.src_exclude_files
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn src_exclude_paths(&self) -> &[String] {
self.src_exclude_paths
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn src_files(&self) -> &[String] {
self.src_files
.as_deref()
.expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
}
pub(crate) fn require_command(&self, context: &str) -> anyhow::Result<&str> {
if self.command.is_empty() {
anyhow::bail!("'command' is not set for processor '{context}'");
}
Ok(&self.command)
}
}
impl AsRef<Self> for StandardConfig {
fn as_ref(&self) -> &Self {
self
}
}
impl KnownFields for StandardConfig {
fn known_fields() -> &'static [&'static str] {
&[
"command",
"formats",
"args",
"dep_inputs",
"dep_auto",
"output_dir",
"required_tools",
"batch",
"max_jobs",
]
}
fn checksum_fields() -> &'static [&'static str] {
&["command", "args"]
}
fn field_descriptions() -> &'static [(&'static str, &'static str)] {
&[
("command", "Path to the tool executable"),
("formats", "Output formats to generate"),
("args", "Extra arguments passed to the tool"),
(
"output_dir",
"Directory where generated output files are written",
),
(
"required_tools",
"Extra tools needed beyond `command` (for wrapper scripts)",
),
]
}
}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct CheckerConfig {
#[serde(flatten)]
pub standard: StandardConfig,
}
impl KnownFields for CheckerConfig {
fn known_fields() -> &'static [&'static str] {
StandardConfig::known_fields()
}
fn checksum_fields() -> &'static [&'static str] {
StandardConfig::checksum_fields()
}
fn field_descriptions() -> &'static [(&'static str, &'static str)] {
StandardConfig::field_descriptions()
}
}
pub type CheckerConfigWithCommand = CheckerConfig;
pub type MarpImagesConfig = CheckerConfig;
pub type JsonSchemaConfig = CheckerConfig;
pub type AsciiConfig = CheckerConfig;
pub type IjqConfig = CheckerConfig;
pub type IjsonlintConfig = CheckerConfig;
pub type IyamllintConfig = CheckerConfig;
pub type ItaploConfig = CheckerConfig;
pub type JekyllConfig = CheckerConfig;
pub type EncodingConfig = CheckerConfig;
pub type DuplicateFilesConfig = CheckerConfig;