use crate::{active_children, arg_of, has_leaf};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct MplsContainerLsp {
pub name: String,
pub to: Option<String>,
pub description: Option<String>,
pub disable: bool,
pub suffix: Option<String>,
pub label_switched_path_template: Option<String>,
pub splitting_merging: bool,
}
pub(super) fn parse_container_lsp(name: &str, lsp: &ConfigLine) -> MplsContainerLsp {
let field = |keyword: &str| arg_of(lsp, keyword).map(str::to_string);
MplsContainerLsp {
name: name.to_string(),
to: field("to"),
description: field("description"),
disable: has_leaf(lsp, "disable"),
suffix: field("suffix"),
label_switched_path_template: field("label-switched-path-template"),
splitting_merging: active_children(lsp)
.any(|c| c.text == "splitting-merging" || c.arg("splitting-merging").is_some()),
}
}