Skip to content

Commit 501bd66

Browse files
committed
Warn about columns that are never found
1 parent a21fa21 commit 501bd66

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/main.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ struct Column<'a> {
137137
subtable: Option<Table<'a>>,
138138
domain: Option<RefCell<Domain<'a>>>,
139139
bbox: Option<BBox>,
140-
multitype: bool
140+
multitype: bool,
141+
used: RefCell<bool>
141142
}
142143

143144
#[derive(Debug)]
@@ -412,7 +413,7 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
412413
eprintln!("Warning: the bbox option has no function without conversion type 'gml-to-ekwb'");
413414
}
414415

415-
let column = Column { name: colname.to_string(), path, serial, datatype, value: RefCell::new(String::new()), attr, hide, include, exclude, trim, convert, find, replace, aggr, subtable, domain, bbox, multitype };
416+
let column = Column { name: colname.to_string(), path, serial, datatype, attr, hide, include, exclude, trim, convert, find, replace, aggr, subtable, domain, bbox, multitype, ..Default::default() };
416417
table.columns.push(column);
417418
}
418419

@@ -588,6 +589,7 @@ fn main() {
588589
}
589590
buf.clear();
590591
}
592+
if !state.settings.hush_warning { check_columns_used(&maintable); }
591593
if !state.settings.hush_info {
592594
let elapsed = start.elapsed().as_secs_f32();
593595
eprintln!("Info: [{}] {} rows processed in {:.*} seconds{}{}",
@@ -601,6 +603,18 @@ fn main() {
601603
}
602604
}
603605

606+
fn check_columns_used(table: &Table) {
607+
for col in &table.columns {
608+
if col.subtable.is_some() {
609+
let sub = col.subtable.as_ref().unwrap();
610+
check_columns_used(sub);
611+
}
612+
else if !*col.used.borrow() {
613+
eprintln!("Warning: table {} column {} was never found", table.name, col.name);
614+
}
615+
}
616+
}
617+
604618
fn process_event(event: &Event, mut state: &mut State) -> Step {
605619
let table = &state.table;
606620
match event {
@@ -814,6 +828,9 @@ fn process_event(event: &Event, mut state: &mut State) -> Step {
814828
}
815829
if state.path == table.path { // This is an end tag of the row path
816830
for i in 0..table.columns.len() {
831+
if !*table.columns[i].used.borrow() && !table.columns[i].value.borrow().is_empty() {
832+
*state.table.columns[i].used.borrow_mut() = true;
833+
}
817834
if let Some(re) = &table.columns[i].include {
818835
if !re.is_match(&table.columns[i].value.borrow()) {
819836
state.filtered = true;

0 commit comments

Comments
 (0)