Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = [
members = ["crates/soar-config",
"crates/soar-db",
"crates/soar-dl",
"crates/soar-utils",
Expand All @@ -25,6 +25,7 @@ diesel = { version = "2.3.2", features = [
"sqlite"
] }
diesel_migrations = { version = "2.3.0", features = ["sqlite"] }
documented = "0.9.2"
fast-glob = "1.0.0"
miette = { version = "7.6.0", features = ["fancy"] }
percent-encoding = "2.3.2"
Expand All @@ -38,11 +39,14 @@ rusqlite = { version = "0.37.0", features = ["bundled", "rusqlite-macros"] }
serde = { version = "1.0.225", features = ["derive"] }
serde_json = { version = "1.0.145", features = ["indexmap"] }
serial_test = "3.2.0"
soar-config = { path = "crates/soar-config" }
soar-core = { path = "soar-core" }
soar-dl = { path = "crates/soar-dl" }
soar-utils = { path = "crates/soar-utils" }
tempfile = "3.10.1"
thiserror = "2.0.17"
toml = "0.9.8"
toml_edit = "0.23.7"
tracing = { version = "0.1.41", default-features = false }
ureq = { version = "3.1.2", features = ["json"] }
url = "2.5.7"
Expand Down
20 changes: 20 additions & 0 deletions crates/soar-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "soar-config"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
readme.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true

[dependencies]
documented = { workspace = true }
miette = { workspace = true }
serde = { workspace = true }
soar-utils = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
toml_edit = { workspace = true }
tracing = { workspace = true }
15 changes: 6 additions & 9 deletions soar-core/src/toml.rs → crates/soar-config/src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use documented::{Documented, DocumentedFields};
use toml_edit::{ArrayOfTables, Decor, Item, RawString, Table};
use tracing::warn;

use crate::error::ConfigError;
use crate::error::{ConfigError, Result};

/// Appends documentation lines as TOML comments to the given `Decor`.
///
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn append_docs_as_toml_comments(decor: &mut Decor, docs: &str) {
///
/// # Returns
/// Returns `Ok(())` if successful, or a `ConfigError` if a TOML item is unexpectedly `None`.
pub fn annotate_toml_table<T>(table: &mut Table, is_root: bool) -> Result<(), ConfigError>
pub fn annotate_toml_table<T>(table: &mut Table, is_root: bool) -> Result<()>
where
T: Documented + DocumentedFields,
{
Expand All @@ -66,9 +66,7 @@ where
Ok(docs) => {
match value_item {
Item::None => {
return Err(ConfigError::Custom(format!(
"Encountered TomlEditItem::None for key '{key_str}' unexpectedly",
)))
return Err(ConfigError::UnexpectedTomlItem(key_str.into()));
}
Item::Value(_) => append_docs_as_toml_comments(key_mut.leaf_decor_mut(), docs),
Item::Table(sub_table) => {
Expand Down Expand Up @@ -105,14 +103,13 @@ where
///
/// # Returns
/// Returns `Ok(())` if annotation succeeds, or a `ConfigError` if annotation fails on the first table.
pub fn annotate_toml_array_of_tables<T>(array: &mut ArrayOfTables) -> Result<(), ConfigError>
pub fn annotate_toml_array_of_tables<T>(array: &mut ArrayOfTables) -> Result<()>
where
T: Documented + DocumentedFields,
{
if let Some(first_table) = array.iter_mut().next() {
annotate_toml_table::<T>(first_table, false).map_err(|err| {
ConfigError::Custom(format!("Failed to annotate first table in array: {err}"))
})?;
annotate_toml_table::<T>(first_table, false)
.map_err(|err| ConfigError::AnnotateFirstTable(err.to_string()))?;
}
Ok(())
}
Loading
Loading