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
11 changes: 10 additions & 1 deletion lib/discovery/aftman.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use serde::Deserialize;
use tracing::warn;

use crate::tool::{ToolAlias, ToolSpec};

Expand Down Expand Up @@ -32,7 +33,15 @@ impl Manifest for AftmanManifest {
where
Self: Sized,
{
toml::from_str(contents).ok()
toml::from_str(contents)
.inspect_err(|e| {
warn!(
"An Aftman manifest could not be parsed!\
\nThe manifest will be ignored and its tools may not be available.\
\nError: {e}",
);
})
.ok()
}

fn into_tools(self) -> HashMap<ToolAlias, ToolSpec> {
Expand Down
45 changes: 31 additions & 14 deletions lib/discovery/foreman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::HashMap, str::FromStr};

use semver::Version;
use toml_edit::{DocumentMut, InlineTable, Table};
use tracing::warn;

use crate::tool::{ToolAlias, ToolId, ToolSpec, util::to_xyz_version};

Expand Down Expand Up @@ -32,30 +33,46 @@ impl Manifest for ForemanManifest {
{
toml_edit::DocumentMut::from_str(contents)
.map(|document| Self { document })
.inspect_err(|e| {
warn!(
"A Foreman manifest could not be parsed!\
\nThe manifest will be ignored and its tools may not be available.\
\nError: {e}",
);
})
.ok()
}

fn into_tools(self) -> HashMap<ToolAlias, ToolSpec> {
let mut tools = HashMap::new();
if let Some(map) = self.document.get("tools").and_then(|t| t.as_table()) {
for (alias, tool_def) in map {
let tool_alias = alias.parse::<ToolAlias>().ok();
let Ok(tool_alias) = alias.parse::<ToolAlias>().inspect_err(|e| {
warn!(
"A Foreman tool alias could not be parsed!\
\nThe tool will be ignored and may not be available.\
\nAlias: {alias}\
\nError: {e}",
);
}) else {
continue;
};

let tool_spec = if tool_def.is_inline_table() {
tool_def
.as_inline_table()
.cloned()
.and_then(|map| parse_foreman_tool_definition(SpecType::InlineTable(map)))
} else {
tool_def
.as_table()
.cloned()
.and_then(|map| parse_foreman_tool_definition(SpecType::Table(map)))
let Some(spec) = tool_def
.as_inline_table()
.cloned()
.map(SpecType::InlineTable)
.or_else(|| tool_def.as_table().cloned().map(SpecType::Table))
.and_then(parse_foreman_tool_definition)
else {
warn!(
"A Foreman tool spec with alias '{tool_alias}' could not be parsed!\
\nThe tool will be ignored and may not be available.",
);
continue;
};

if let (Some(alias), Some(spec)) = (tool_alias, tool_spec) {
tools.insert(alias, spec);
}
tools.insert(tool_alias, spec);
}
}
tools
Expand Down