diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 19 |
1 files 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<PathBuf, OsString> { + 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<PathBuf> } 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 = { |