Skip to content

Commit

Permalink
Allow absence of [modules] in TOML file.
Browse files Browse the repository at this point in the history
Making the modules field of LogSpecification an Option allows it to be
omitted entirely.  This makes an empty log spec TOML valid.

Signed-off-by: Ian Jackson <[email protected]>
  • Loading branch information
ijackson committed Sep 5, 2020
1 parent 674d0b8 commit 1211a5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/log_specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl LogSpecification {
struct LogSpecFileFormat {
pub global_level: Option<String>,
pub global_pattern: Option<String>,
pub modules: std::collections::BTreeMap<String, String>,
pub modules: Option<std::collections::BTreeMap<String, String>>,
}

let logspec_ff: LogSpecFileFormat = toml::from_str(s)?;
Expand All @@ -266,7 +266,7 @@ impl LogSpecification {
});
}

for (k, v) in logspec_ff.modules {
for (k, v) in logspec_ff.modules.unwrap_or_default() {
module_filters.push(ModuleFilter {
module_name: Some(k),
level_filter: parse_level_filter(v)?,
Expand Down Expand Up @@ -872,6 +872,11 @@ mod test_with_specfile {

#[test]
fn specfile() {
compare_specs(
"",
"",
);

compare_specs(
"[modules]\n\
",
Expand Down

0 comments on commit 1211a5f

Please sign in to comment.