Skip to content

Commit

Permalink
Merge pull request #129 from lqd/fix_clap
Browse files Browse the repository at this point in the history
Make clap usable, add warnings on missing fact files
  • Loading branch information
nikomatsakis authored Oct 3, 2019
2 parents c78359a + 86c9639 commit 1f31a28
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/tab_delim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,40 @@ fn load_tab_delimited_file<Row>(tables: &mut InternerTables, path: &Path) -> io:
where
Row: for<'input> FromTabDelimited<'input>,
{
let file = File::open(path)?;
match File::open(path) {
Ok(file) => io::BufReader::new(file)
.lines()
.enumerate()
.map(|(index, line)| {
let line = line?;
let mut columns = line.split('\t');
let row = match FromTabDelimited::parse(tables, &mut columns) {
None => {
error!("error parsing line {} of `{}`", index + 1, path.display());
process::exit(1);
}

io::BufReader::new(file)
.lines()
.enumerate()
.map(|(index, line)| {
let line = line?;
let mut columns = line.split('\t');
let row = match FromTabDelimited::parse(tables, &mut columns) {
None => {
error!("error parsing line {} of `{}`", index + 1, path.display());
Some(v) => v,
};

if columns.next().is_some() {
error!("extra data on line {} of `{}`", index + 1, path.display());
process::exit(1);
}

Some(v) => v,
};

if columns.next().is_some() {
error!("extra data on line {} of `{}`", index + 1, path.display());
process::exit(1);
}
Ok(row)
})
.collect(),

Ok(row)
})
.collect()
Err(e) => {
error!(
"Error opening file '{}': {}. Defaulting to empty relation",
path.display(),
e
);
Ok(Vec::new())
}
}
}

impl<'input, T> FromTabDelimited<'input> for T
Expand Down

0 comments on commit 1f31a28

Please sign in to comment.