summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/main.rs b/src/main.rs
index 8874ea9..37644c0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,42 +1,30 @@
-extern crate regex;
-#[macro_use] extern crate lazy_static;
-extern crate structopt;
-#[macro_use] extern crate structopt_derive;
-
pub mod qif;
-use structopt::StructOpt;
-
+use clap::Parser;
use 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::error::Error;
-
-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")]
+use std::{
+ error::Error,
+ fs::File,
+ io::{prelude::*, *},
+ path::PathBuf,
+ result::Result,
+};
+
+/// Qif file preprocessor to decrease duplication when importing to gnucash
+#[derive(Parser, Debug)]
+#[structopt(
+ name = "Qif Parser",
+ version, about, long_about = None
+)]
struct CliArgs {
- #[structopt(help = "Files to preprocess", required, parse(try_from_os_str="parse_filepath"))]
- files: Vec<PathBuf>
+ /// Files to preprocess
+ #[arg(value_hint = clap::ValueHint::FilePath)]
+ files: Vec<PathBuf>,
}
-fn main() -> Result<(), Box<Error>> {
- let args = CliArgs::from_args();
-
+fn main() -> Result<(), Box<dyn Error>> {
+ let args = CliArgs::parse();
+
for filepath in &args.files {
let file = File::open(filepath)?;
let file_reader = BufReader::new(file);