Support commenting out overlays

This commit is contained in:
2023-11-04 19:43:59 -04:00
parent fa8e121ffd
commit ea995ddf7b
4 changed files with 25 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "mkoverlay"
version = "1.5.1"
version = "1.6.0"
edition = "2021"
[profile.release]

View File

@@ -7,7 +7,10 @@ pub fn read_config(input: Input) -> Result<OverlayDesc, Error> {
if let Some(objects) = json_reader.as_object() {
for object in objects {
overlay_desc.push(read_as_slot(object)?);
let slot = read_as_slot(object)?;
if !slot.is_commented_out() && slot.has_sections() {
overlay_desc.push(slot);
}
}
Ok(overlay_desc)
@@ -24,7 +27,10 @@ fn read_as_slot(json_value: (&String, &serde_json::Value)) -> Result<OverlaySlot
if let Some(json_value) = json_value.as_object() {
for (name, json_value) in json_value {
slot.add_section(read_as_section(name.clone(), json_value)?);
let section = read_as_section(name.clone(), json_value)?;
if !section.is_commented_out() {
slot.add_section(section);
}
}
}

View File

@@ -2,6 +2,8 @@ pub mod json_reader;
pub type OverlayDesc = Vec<OverlaySlot>;
const COMMENT_PREFIX:char = '!';
pub struct OverlaySlot {
pub(super) name: String,
pub(super) sections: Vec<OverlaySection>
@@ -15,6 +17,14 @@ impl OverlaySlot {
pub fn add_section(&mut self, section: OverlaySection) {
self.sections.push(section);
}
pub fn is_commented_out(&self) -> bool {
self.name.starts_with(COMMENT_PREFIX)
}
pub fn has_sections(&self) -> bool {
!self.sections.is_empty()
}
}
pub struct OverlaySection {
@@ -30,4 +40,8 @@ impl OverlaySection {
pub fn add_file_pattern(&mut self, file_pattern: String) {
self.file_pattern.push(file_pattern);
}
pub fn is_commented_out(&self) -> bool {
self.name.starts_with(COMMENT_PREFIX)
}
}