commit c585e349a6635693018ffd22ae9472217272f452
parent 42e504ae010254d3c4861dd0d4a06fc9de7d4f93
Author: Andy Khramtsov <>
Date: Sun, 8 Feb 2026 00:41:34 +0300
feat: yaml inventory
Diffstat:
5 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -472,6 +472,7 @@ dependencies = [
"indexmap",
"serde",
"serde_json",
+ "serde_yaml",
"test-log",
"thiserror",
"tokio",
@@ -724,6 +725,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
+name = "ryu"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
+
+[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -788,6 +795,19 @@ dependencies = [
]
[[package]]
+name = "serde_yaml"
+version = "0.9.34+deprecated"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
+dependencies = [
+ "indexmap",
+ "itoa",
+ "ryu",
+ "serde",
+ "unsafe-libyaml",
+]
+
+[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1103,6 +1123,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
[[package]]
+name = "unsafe-libyaml"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
+
+[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -10,6 +10,7 @@ dialoguer = "0.12.0"
indexmap = "2.13.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
+serde_yaml = "0.9.34"
test-log = { version = "0.2.19", features = ["trace"] }
thiserror = "2.0.17"
tokio = { version = "1.49.0", features = ["rt-multi-thread", "fs"] }
diff --git a/src/config/mod.rs b/src/config/mod.rs
@@ -8,6 +8,8 @@ pub struct Config {
pub logging: logging::LoggingConfig,
pub root: PathBuf,
#[serde(default)]
+ pub inventory_format: InventoryFormat,
+ #[serde(default)]
pub filters: Vec<Filter>,
}
@@ -20,6 +22,14 @@ impl Config {
}
}
+#[derive(Clone, Debug, Default, serde::Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum InventoryFormat {
+ #[default]
+ Yaml,
+ Json,
+}
+
#[derive(Clone, Debug, serde::Deserialize)]
pub struct Filter {
pub path: PathBuf,
diff --git a/src/lib.rs b/src/lib.rs
@@ -230,7 +230,7 @@ fn print(tree: &Filetree<Meta>) -> Result<(), Error> {
let offset_text = " ".repeat(offset);
if let Some(msg) = node.borrow().meta().inventory.as_ref() {
println!(
- "{}\x1b[2m|\x1b[0m \x1b[32m/{}\x1b[0m {}",
+ "{}\x1b[2m|\x1b[0m \x1b[32m/{}\x1b[0m \x1b[3m{}\x1b[0m",
offset_text,
name,
msg.trim()
diff --git a/src/state.rs b/src/state.rs
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use tokio::runtime::Runtime;
use crate::{
- config::Config,
+ config::{Config, InventoryFormat},
filetree::{self, Filetree, node::Node},
inventory::{self, Inventory},
};
@@ -25,13 +25,23 @@ impl State {
.build()
.map_err(Error::Runtime)?;
- let inventory_path = config_dir.join("inventory.json");
+ let inventory_path = match config.inventory_format {
+ InventoryFormat::Yaml => config_dir.join("inventory.yaml"),
+ InventoryFormat::Json => config_dir.join("inventory.json"),
+ };
let inventory = runtime
.block_on(tokio::fs::read(inventory_path))
.map_err(Error::ReadFile)?;
- let inventory: Inventory =
- serde_json::from_slice(inventory.as_slice()).map_err(Error::Json)?;
+
+ let inventory: Inventory = match config.inventory_format {
+ InventoryFormat::Yaml => {
+ serde_yaml::from_slice(inventory.as_slice()).map_err(Error::Yaml)?
+ }
+ InventoryFormat::Json => {
+ serde_json::from_slice(inventory.as_slice()).map_err(Error::Json)?
+ }
+ };
let mut blacklist_tree = Filetree::new(Node::new("/".into(), ()));
let mut whitelist_tree = Filetree::new(Node::new("/".into(), ()));
@@ -126,6 +136,8 @@ pub enum Error {
Runtime(tokio::io::Error),
#[error("Error reading file: {0}")]
ReadFile(std::io::Error),
+ #[error("Error parsing yaml: {0}")]
+ Yaml(serde_yaml::Error),
#[error("Error parsing json: {0}")]
Json(serde_json::Error),
#[error("Error building filetree: {0}")]