Skip to content

Commit a21fa21

Browse files
committed
Make single-col one-to-many relation inherit incl/excl options
1 parent 02fb5d1 commit a21fa21

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io::{Read, Write, BufReader, BufRead, stdin, stdout};
22
use std::fs::{File, OpenOptions};
3+
use std::mem;
34
use std::path::Path;
45
use std::env;
56
use std::cell::{ Cell, RefCell };
@@ -288,6 +289,8 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
288289
_ => None
289290
};
290291
let mut datatype = col["type"].as_str().unwrap_or("text").to_string();
292+
let mut include: Option<Regex> = col["incl"].as_str().map(|str| Regex::new(str).unwrap_or_else(|err| fatalerr!("Error: invalid regex in 'incl' entry in configuration file: {}", err)));
293+
let mut exclude: Option<Regex> = col["excl"].as_str().map(|str| Regex::new(str).unwrap_or_else(|err| fatalerr!("Error: invalid regex in 'excl' entry in configuration file: {}", err)));
291294
let norm = col["norm"].as_str();
292295
let file = col["file"].as_str();
293296
let cardinality = match (file, norm) { // The combination of 'file' and 'norm' options determine relation to the subtable (if any)
@@ -302,7 +305,7 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
302305
let filename = col["file"].as_str().unwrap();
303306
if table.columns.is_empty() { fatalerr!("Error: table '{}' cannot have a subtable as first column", name); }
304307
let mut subtable = add_table(colname, &path, Some(filename), settings, &[], cardinality);
305-
subtable.columns.push(Column { name: colname.to_string(), path: path.clone(), datatype: datatype.to_string(), ..Default::default() });
308+
subtable.columns.push(Column { name: colname.to_string(), path: path.clone(), datatype: datatype.to_string(), include: mem::take(&mut include), exclude: mem::take(&mut exclude), ..Default::default() });
306309
emit_preamble(&subtable, settings, Some(format!("{} {}", name, table.columns[0].datatype)));
307310
Some(subtable)
308311
},
@@ -311,7 +314,7 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
311314
if table.columns.is_empty() { fatalerr!("Error: table '{}' cannot have a subtable as first column", name); }
312315
let mut subtable = add_table(colname, &path, Some(filename), settings, &[], cardinality);
313316
// subtable.columns.push(Column { name: String::from("id"), path: String::new(), datatype: String::from("integer"), ..Default::default() });
314-
subtable.columns.push(Column { name: colname.to_string(), path: path.clone(), datatype: "integer".to_string(), ..Default::default() });
317+
subtable.columns.push(Column { name: colname.to_string(), path: path.clone(), datatype: "integer".to_string(), include: mem::take(&mut include), exclude: mem::take(&mut exclude), ..Default::default() });
315318
emit_preamble(&subtable, settings, Some(format!("{} {}", name, table.columns[0].datatype)));
316319
Some(subtable)
317320
},
@@ -340,8 +343,6 @@ fn add_table<'a>(name: &str, rowpath: &str, outfile: Option<&str>, settings: &Se
340343
}
341344
};
342345
let hide = col["hide"].as_bool().unwrap_or(false);
343-
let include: Option<Regex> = col["incl"].as_str().map(|str| Regex::new(str).unwrap_or_else(|err| fatalerr!("Error: invalid regex in 'incl' entry in configuration file: {}", err)));
344-
let exclude: Option<Regex> = col["excl"].as_str().map(|str| Regex::new(str).unwrap_or_else(|err| fatalerr!("Error: invalid regex in 'excl' entry in configuration file: {}", err)));
345346
let trim = col["trim"].as_bool().unwrap_or(false);
346347
let attr = col["attr"].as_str();
347348
let convert = col["conv"].as_str();

0 commit comments

Comments
 (0)