From 4823481be1e902a539a8eb538ec42c81919ee154 Mon Sep 17 00:00:00 2001 From: Clownxz Date: Sat, 13 Jul 2024 00:35:38 -0400 Subject: [PATCH 1/4] Fix failing to parse tool specifications in foreman.toml --- lib/discovery/foreman.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/discovery/foreman.rs b/lib/discovery/foreman.rs index 7b7ac8f..6545a05 100644 --- a/lib/discovery/foreman.rs +++ b/lib/discovery/foreman.rs @@ -35,7 +35,9 @@ impl Manifest for ForemanManifest { 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::().ok(); - let tool_spec = tool_def.as_table().and_then(parse_foreman_tool_definition); + let tool_spec = tool_def + .as_inline_table() + .and_then(parse_foreman_tool_definition); if let (Some(alias), Some(spec)) = (tool_alias, tool_spec) { tools.insert(alias, spec); } @@ -45,7 +47,7 @@ impl Manifest for ForemanManifest { } } -fn parse_foreman_tool_definition(map: &toml_edit::Table) -> Option { +fn parse_foreman_tool_definition(map: &toml_edit::InlineTable) -> Option { let version = map.get("version").and_then(|t| t.as_str()).and_then(|v| { // TODO: Support real version requirements instead of just exact/min versions let without_prefix = v.trim_start_matches('=').trim_start_matches('^'); From db0b4a46b223d0424acbb0f9dbd1ef38a4ab52b3 Mon Sep 17 00:00:00 2001 From: Clownxz Date: Sat, 13 Jul 2024 02:22:48 -0400 Subject: [PATCH 2/4] Support both tables and inline tables for foreman.toml manifest --- lib/discovery/foreman.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/discovery/foreman.rs b/lib/discovery/foreman.rs index 6545a05..8f638d3 100644 --- a/lib/discovery/foreman.rs +++ b/lib/discovery/foreman.rs @@ -1,12 +1,17 @@ use std::{collections::HashMap, str::FromStr}; use semver::Version; -use toml_edit::DocumentMut; +use toml_edit::{DocumentMut, InlineTable, Table}; use crate::tool::{ToolAlias, ToolId, ToolSpec}; use super::Manifest; +enum SpecType { + InlineTable(InlineTable), + Table(Table), +} + #[derive(Debug, Clone)] pub(crate) struct ForemanManifest { document: DocumentMut, @@ -35,9 +40,19 @@ impl Manifest for ForemanManifest { 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::().ok(); - let tool_spec = tool_def - .as_inline_table() - .and_then(parse_foreman_tool_definition); + + 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))) + }; + if let (Some(alias), Some(spec)) = (tool_alias, tool_spec) { tools.insert(alias, spec); } @@ -47,7 +62,12 @@ impl Manifest for ForemanManifest { } } -fn parse_foreman_tool_definition(map: &toml_edit::InlineTable) -> Option { +fn parse_foreman_tool_definition(map: SpecType) -> Option { + let map = match map { + SpecType::InlineTable(table) => table, + SpecType::Table(table) => table.into_inline_table(), + }; + let version = map.get("version").and_then(|t| t.as_str()).and_then(|v| { // TODO: Support real version requirements instead of just exact/min versions let without_prefix = v.trim_start_matches('=').trim_start_matches('^'); From 2feaf8d060e6e9e962ff703fb81c5784a738ecd8 Mon Sep 17 00:00:00 2001 From: Clownxz Date: Sat, 13 Jul 2024 02:26:47 -0400 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d73916..1236de5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Failed to parse tool specifications in foreman.toml if they were an inline table + ## `0.1.4` - July 11th, 2024 ### Fixed From eeadc28e3ba1655c469659b6628edeaf68648111 Mon Sep 17 00:00:00 2001 From: Clownxz Date: Sat, 13 Jul 2024 02:29:33 -0400 Subject: [PATCH 4/4] Mention pull-request in CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1236de5..cb02fd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Failed to parse tool specifications in foreman.toml if they were an inline table +- Failed to parse tool specifications in foreman.toml if they were an inline table ([#36]) + +[#36]: https://github.com/rojo-rbx/rokit/pull/36 ## `0.1.4` - July 11th, 2024