From 8d8af5cf3d4e3f62571065221d110f82b40135c8 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Fri, 5 Jan 2018 19:57:13 +0200 Subject: Moved check for filepath being a file to the parsing stage --- src/main.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 66c3caa..a24d35e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,26 +8,31 @@ use qif_parser::qif::*; use std::io::prelude::*; use std::io::*; +use std::ffi::{OsString, OsStr}; use std::path::PathBuf; +use std::result::Result; use std::fs::File; use std::process; +fn parse_filepath(str: &OsStr) -> Result { + let path: PathBuf = ::std::convert::From::from(str); + if path.is_file() { + Ok(path) + } else { + Err(str.to_os_string()) + } +} + #[derive(StructOpt, Debug)] #[structopt(name = "Qif Parser", about = "Qif file preprocessor to decrease duplication when importing to gnucash")] struct CliArgs { - #[structopt(help = "Files to preprocess", required, parse(from_os_str))] + #[structopt(help = "Files to preprocess", required, parse(try_from_os_str="parse_filepath"))] files: Vec } fn main() { let args = CliArgs::from_args(); - for filepath in &args.files { - if !filepath.is_file() { - eprintln!("{} is not a file", filepath.display()); - process::exit(1); - } - } for filepath in &args.files { let qif_result = { -- cgit v1.2.3