Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 11 additions & 20 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resolver = "3"

[dependencies]
clap = { version = "4", features = ["derive"] }
toml = "0.8"
toml = "0.9"
serde = { version = "1", features = ["derive"] }
include_dir = "0.7"
liquid = "0.26"
Expand Down
15 changes: 15 additions & 0 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ pub struct Topology {
}

impl Topology {
/// Parse topology toml file and validate the fields.
/// Emit warning upon meeting alien fields.
pub fn parse_toml(path: &PathBuf) -> Result<Self> {
let content = fs::read_to_string(path)
.context(format!("failed to read topology from {}", path.display()))?;

let deserializer = toml::de::Deserializer::parse(&content)
.context(format!("failed to parse topology from {}", path.display()))?;

serde_ignored::deserialize(deserializer, |f| {
warn!("Unknown field in topology TOML: {f}");
})
.map_err(anyhow::Error::from)
}

fn find_plugin_versions(&mut self, plugins_dir: &Path) -> Result<()> {
for (plugin_name, plugin) in &mut self.plugins {
let current_plugin_dir = plugins_dir.join(plugin_name);
Expand Down
17 changes: 1 addition & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::{bail, Context, Result};
use clap::{Parser, Subcommand};
use log::warn;
use nix::unistd::{fork, ForkResult};
use std::{
env, fs,
Expand Down Expand Up @@ -375,21 +374,7 @@ fn main() -> Result<()> {
run_child_killer();
}

// Parse topology toml file and validate the fields
// Emit warning upon meeting alien fields
let topology: commands::run::Topology = serde_ignored::deserialize(
toml::de::Deserializer::new(
&fs::read_to_string(plugin_path.join(&topology))
.context(format!("failed to read {}", &topology.display()))?,
),
|path| {
warn!("Unknown field {path}");
},
)
.context(format!(
"failed to parse .toml file of {}",
topology.display()
))?;
let topology = commands::run::Topology::parse_toml(&plugin_path.join(topology))?;

let params = commands::run::ParamsBuilder::default()
.topology(topology)
Expand Down
Loading