diff --git a/Cargo.toml b/Cargo.toml
index a1b2c3d..e4f5g6h 100644
@@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
regex = "1.10"
yaml-rust = "0.4"
@@ -12,3 +13,8 @@ regex = "1.10"
[dev-dependencies]
insta = "1.43"
proptest = "1.9"
+
+[features]
+default = ["logging"]
+logging = []
+strict-mode = []
diff --git a/src/lib.rs b/src/lib.rs
index 1234567..abcdefg 100644
@@ -1,5 +1,6 @@
//! AnyRepair Library
+#[cfg(feature = "logging")]
use std::env;
use crate::error::RepairError;
@@ -10,6 +11,7 @@ pub mod json;
pub mod yaml;
pub mod markdown;
pub mod diff;
+pub mod config;
pub use error::{RepairError, Result};
pub use traits::Repair;
@@ -20,6 +22,7 @@ pub use json::JsonRepairer;
pub use diff::DiffRepairer;
/// Main repair function with auto-detection
+#[inline]
pub fn repair(content: &str) -> Result<String> {
let trimmed = content.trim();
@@ -35,6 +38,7 @@ pub fn repair(content: &str) -> Result<String> {
}
}
+#[cfg(feature = "logging")]
fn log_repair(format: &str, success: bool) {
if env::var("ANYREPAIR_LOG").is_ok() {
eprintln!("[anyrepair] {} repair: {}", format, if success { "success" } else { "failed" });
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..1234567
@@ -0,0 +1,50 @@
+//! Configuration management for repair operations
+
+use serde::{Deserialize, Serialize};
+use std::path::Path;
+use std::fs;
+
+/// Repair configuration
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct Config {
+ pub max_iterations: usize,
+ pub enable_logging: bool,
+ pub strict_mode: bool,
+ pub formats: FormatConfig,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct FormatConfig {
+ pub json: JsonConfig,
+ pub yaml: YamlConfig,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct JsonConfig {
+ pub fix_trailing_commas: bool,
+ pub fix_missing_quotes: bool,
+ pub preserve_comments: bool,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct YamlConfig {
+ pub fix_indentation: bool,
+ pub preserve_comments: bool,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ Self {
+ max_iterations: 10,
+ enable_logging: false,
+ strict_mode: false,
+ formats: FormatConfig {
+ json: JsonConfig {
+ fix_trailing_commas: true,
+ fix_missing_quotes: true,
+ preserve_comments: false,
+ },
+ yaml: YamlConfig {
+ fix_indentation: true,
+ preserve_comments: true,
+ },
+ },
+ }
+ }
+}
+
+impl Config {
+ pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn std::error::Error>> {
+ let content = fs::read_to_string(path)?;
+ let config: Config = toml::from_str(&content)?;
+ Ok(config)
+ }
+}