Skip to content

Remove implicit usage of FromStr for PathBuf #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use crate::intern;
use crate::output::Output;
use crate::tab_delim;
use failure::Error;
use std::path::Path;
use std::time::{Duration, Instant};
use structopt::StructOpt;

use std::io;
use std::path::PathBuf;

arg_enum! {
#[derive(Debug, Clone, Copy)]
pub enum Algorithm {
Expand All @@ -28,39 +26,42 @@ pub struct Opt {
#[structopt(short = "v")]
verbose: bool,
#[structopt(short = "o", long = "output")]
output_directory: Option<PathBuf>,
output_directory: Option<String>,
#[structopt(raw(required = "true"))]
fact_dirs: Vec<PathBuf>,
fact_dirs: Vec<String>,
}

pub fn main(opt: Opt) -> Result<(), Error> {
do catch {
let output_directory = opt
.output_directory
.map(|x| {Path::new(&x).to_owned()} );
for facts_dir in opt.fact_dirs {
let tables = &mut intern::InternerTables::new();

let result: Result<(Duration, Output), Error> = do catch {
let verbose = opt.verbose;
let algorithm = opt.algorithm;
let all_facts = tab_delim::load_tab_delimited_facts(tables, &facts_dir)?;
let all_facts = tab_delim::load_tab_delimited_facts(tables, &Path::new(&facts_dir))?;
timed(|| Output::compute(all_facts, algorithm, verbose))
};

match result {
Ok((duration, output)) => {
println!("--------------------------------------------------");
println!("Directory: {}", facts_dir.display());
println!("Directory: {}", facts_dir);
if !opt.skip_timing {
let seconds: f64 = duration.as_secs() as f64;
let millis: f64 = duration.subsec_nanos() as f64 * 0.000_000_001_f64;
println!("Time: {:0.3}s", seconds + millis);
}
if !opt.skip_tuples {
output.dump(&opt.output_directory, tables).expect("Failed to write output");
output.dump(&output_directory, tables).expect("Failed to write output");
}
}

Err(error) => {
eprintln!("`{}`: {}", facts_dir.display(), error);
eprintln!("`{}`: {}", facts_dir, error);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ impl Output {
// create a writer for the provided output.
// If we have an output directory use that, otherwise just dump to stdout
use std::fs;
use std::path::Path;

Ok(match out_dir {
Some(dir) => {
Expand Down