Skip to content

Commit 205bcb9

Browse files
committed
Add aggregate option "last" and verify option input
1 parent 4999728 commit 205bcb9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/main.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
259259
let mut subtable: Option<Table> = match col["cols"].is_badvalue() {
260260
true => None,
261261
false => {
262+
if table.columns.is_empty() { fatalerr!("Error: table '{}' cannot have a subtable as first column", name); }
262263
let filename = col["file"].as_str().unwrap_or_else(|| fatalerr!("Error: subtable {} has no 'file' entry", colname));
263264
Some(add_table(colname, &path, Some(filename), settings, col["cols"].as_vec().unwrap_or_else(|| fatalerr!("Error: subtable 'cols' entry is not an array")), Some(format!("{} {}", name, table.columns[0].datatype))))
264265
}
@@ -294,12 +295,17 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
294295

295296
if let Some(val) = convert {
296297
if !vec!("xml-to-text", "gml-to-ewkb").contains(&val) {
297-
fatalerr!("Error: option 'convert' contains invalid value: {}", val);
298+
fatalerr!("Error: table '{}' option 'conv' contains invalid value: {}", name, val);
298299
}
299300
if val == "gml-to-ewkb" && !settings.hush_notice {
300301
eprintln!("Notice: gml-to-ewkb conversion is experimental and in no way complete or standards compliant; use at your own risk");
301302
}
302303
}
304+
if let Some(val) = aggr {
305+
if !vec!("first", "last", "append").contains(&val) {
306+
fatalerr!("Error: table '{}' option 'aggr' contains invalid value: {}", name, val);
307+
}
308+
}
303309
if include.is_some() || exclude.is_some() {
304310
if convert.is_some() {
305311
fatalerr!("Error: filtering (incl/excl) and 'conv' cannot be used together on a single column");
@@ -523,7 +529,10 @@ fn main() {
523529
if let Ok(key) = reader.decode(attr.key) {
524530
if key == request {
525531
if let Ok(value) = reader.decode(&attr.value) {
526-
if !table.columns[i].value.borrow().is_empty() && !allow_iteration(&table.columns[i], &settings) { break; }
532+
if !table.columns[i].value.borrow().is_empty() {
533+
if !allow_iteration(&table.columns[i], &settings) { break; }
534+
if let Some("last") = table.columns[i].aggr { table.columns[i].value.borrow_mut().clear(); }
535+
}
527536
table.columns[i].value.borrow_mut().push_str(value)
528537
}
529538
else if !settings.hush_warning { eprintln!("Warning: failed to decode attribute {} for column {}", request, table.columns[i].name); }
@@ -587,6 +596,7 @@ fn main() {
587596
if table.columns[i].attr.is_some() || table.columns[i].serial.is_some() { break; }
588597
if !table.columns[i].value.borrow().is_empty() {
589598
if !allow_iteration(&table.columns[i], &settings) { break; }
599+
if let Some("last") = table.columns[i].aggr { table.columns[i].value.borrow_mut().clear(); }
590600
}
591601

592602
let unescaped = e.unescaped().unwrap_or_else(|err| fatalerr!("Error: failed to unescape XML text node '{}': {}", String::from_utf8_lossy(e), err));
@@ -766,6 +776,7 @@ fn allow_iteration(column: &Column, settings: &Settings) -> bool {
766776
false
767777
},
768778
Some("first") => false,
779+
Some("last") => true,
769780
Some("append") => {
770781
if !column.value.borrow().is_empty() { column.value.borrow_mut().push(','); }
771782
true

0 commit comments

Comments
 (0)