add namespaces #8
1 changed files with 24 additions and 1 deletions
|
@ -54,8 +54,10 @@ where
|
||||||
let trimmed_line = line.trim_start_matches(['#', ' ']);
|
let trimmed_line = line.trim_start_matches(['#', ' ']);
|
||||||
if should_enable_variable(&choose_sections, &cur_sections) {
|
if should_enable_variable(&choose_sections, &cur_sections) {
|
||||||
String::from(trimmed_line)
|
String::from(trimmed_line)
|
||||||
} else {
|
} else if should_disable_variable(&choose_sections, &cur_sections) {
|
||||||
format!("# {}", trimmed_line)
|
format!("# {}", trimmed_line)
|
||||||
|
} else {
|
||||||
|
line.to_string()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
line.to_string()
|
line.to_string()
|
||||||
|
@ -97,6 +99,19 @@ fn should_enable_variable(choose_sections: &[Section], current_sections: &[Secti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_disable_variable(choose_sections: &[Section], current_sections: &[Section]) -> bool {
|
||||||
|
choose_sections.is_empty()
|
||||||
|
|| choose_sections.iter().any(|s| s.namespace.is_none())
|
||||||
|
|| !choose_sections
|
||||||
|
.iter()
|
||||||
|
.filter(|s| s.namespace.is_some())
|
||||||
|
.any(|s| {
|
||||||
|
current_sections
|
||||||
|
.iter()
|
||||||
|
.any(|s2| s.namespace == s2.namespace)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -221,5 +236,13 @@ mod tests {
|
||||||
]
|
]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_disable_variables() {
|
||||||
|
assert!(should_disable_variable(
|
||||||
|
&[Section::with_namespace("debug", "on")],
|
||||||
|
&[Section::new("local")]
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue