diff options
| author | lukeflo | 2025-05-18 22:44:36 +0200 |
|---|---|---|
| committer | lukeflo | 2025-05-24 14:24:40 +0200 |
| commit | 7fe5acb85b9e665ec83f590942ee78b8c90d6aae (patch) | |
| tree | 979fc66155ca60ee9bc167cf32348fa8bbdf8c31 /src/cliargs.rs | |
| parent | 1dcb24c381990bdead5fa3df2fb95d74b176a8c1 (diff) | |
| download | bibiman-7fe5acb85b9e665ec83f590942ee78b8c90d6aae.tar.gz bibiman-7fe5acb85b9e665ec83f590942ee78b8c90d6aae.zip | |
first tests for pdf folder
Diffstat (limited to 'src/cliargs.rs')
| -rw-r--r-- | src/cliargs.rs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/cliargs.rs b/src/cliargs.rs index d4fac46..6fd30e1 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -33,6 +33,7 @@ pub struct CLIArgs { pub pos_args: Vec<PathBuf>, pub cfg_path: Option<PathBuf>, pub light_theme: bool, + pub pdf_files: Option<Vec<PathBuf>>, } impl CLIArgs { @@ -55,6 +56,10 @@ impl CLIArgs { Short('v') | Long("version") => args.versionarg = true, Short('c') | Long("config-file") => args.cfg_path = Some(parser.value()?.parse()?), Long("light-terminal") => args.light_theme = true, + Long("merge-pdf-paths") => { + let pdf_dir: PathBuf = parser.value()?.parse()?; + args.pdf_files = collect_pdf_files(pdf_dir); + } // Value(pos_arg) => parse_files(&mut args, pos_arg), Value(pos_arg) => args.pos_args.push(pos_arg.into()), _ => return Err(arg.unexpected()), @@ -65,6 +70,37 @@ impl CLIArgs { } } +/// This function walks the given dir and collects all pdf files into a `Vec` +pub fn collect_pdf_files(pdf_dir: PathBuf) -> Option<Vec<PathBuf>> { + let mut files: Vec<PathBuf> = Vec::new(); + + // Expand tilde to /home/user + let pdf_dir = if pdf_dir.starts_with("~") { + app::expand_home(&pdf_dir) + } else { + pdf_dir + }; + + // Walk the passed dir and collect all pdf files into vec + if pdf_dir.is_dir() { + for file in WalkDir::new(pdf_dir) { + let f = file.unwrap().into_path(); + if f.is_file() + && f.extension().is_some() + && f.extension().unwrap_or_default().to_ascii_lowercase() == "pdf" + { + files.push(f); + } + } + } + + if files.is_empty() { + None + } else { + Some(files) + } +} + /// This function maps a vector containing paths to another vector containing paths. /// But it will walk all entries of the first vec which are directories /// and put only valid file paths with `.bib` ending to the resulting vec. @@ -126,7 +162,10 @@ FLAGS: -v, --version Show the version and exit -c, --config-file Path to config file used for current session. Takes precedence over standard config file. - --light-terminal Enable color mode for light terminal background", + --light-terminal Enable color mode for light terminal background + --merge-pdf-paths Merge PDF files named by citekey at the given path into + the `file` field of the entry matching the citekey + (might not work with citekeys containing special chars)", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), ); |
