diff options
| author | lukeflo | 2024-11-22 15:30:23 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-22 15:30:23 +0100 |
| commit | 19d55db7430bc943dad5e7e4ffcd79692caada0d (patch) | |
| tree | f63391ee01f3669814bc367bb6e81e7348d83b49 | |
| parent | e5274a2e0c3c6ba62d12420d487e3725e154cee4 (diff) | |
| download | bibiman-19d55db7430bc943dad5e7e4ffcd79692caada0d.tar.gz bibiman-19d55db7430bc943dad5e7e4ffcd79692caada0d.zip | |
add crates
| -rw-r--r-- | Cargo.lock | 36 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/bibiman/bibisetup.rs | 22 |
3 files changed, 43 insertions, 17 deletions
@@ -80,6 +80,7 @@ dependencies = [ "editor-command", "futures", "itertools", + "lexopt", "nucleo-matcher", "ratatui", "sarge", @@ -87,6 +88,7 @@ dependencies = [ "tokio", "tokio-util", "tui-input", + "walkdir", ] [[package]] @@ -655,6 +657,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] +name = "lexopt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401" + +[[package]] name = "libc" version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1081,6 +1089,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] name = "sarge" version = "7.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1452,6 +1469,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1553,6 +1580,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -24,6 +24,7 @@ crossterm = { version = "0.28.1", features = ["event-stream"] } editor-command = "0.1.1" futures = "0.3.30" itertools = "0.13.0" +lexopt = "0.3.0" nucleo-matcher = "0.3.1" ratatui = { version = "0.29.0", features = ["unstable-rendered-line-info"]} sarge = "7.2.5" @@ -31,3 +32,4 @@ signal-hook = "0.3.17" tokio = { version = "1.39.3", features = ["full"] } tokio-util = "0.7.12" tui-input = "0.11.0" +walkdir = "2.5.0" diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 227d0b2..ad413a4 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -17,7 +17,6 @@ use biblatex::{self, Bibliography}; use biblatex::{ChunksExt, Type}; -use color_eyre::eyre::Result; use color_eyre::owo_colors::OwoColorize; use itertools::Itertools; use std::ffi::OsString; @@ -54,7 +53,7 @@ pub struct BibiData { impl BibiSetup { pub fn new(main_bibfiles: &[PathBuf]) -> Self { // TODO: Needs check for config file path as soon as config file is impl - Self::check_files(main_bibfiles).expect("Something went wrong checking files"); + Self::check_files(main_bibfiles); let bibfilestring = Self::bibfiles_to_string(main_bibfiles); let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap(); let citekeys = Self::get_citekeys(&bibliography); @@ -71,7 +70,7 @@ impl BibiSetup { } // Check which file format the passed file has - fn check_files(main_bibfiles: &[PathBuf]) -> Result<()> { + fn check_files(main_bibfiles: &[PathBuf]) { if main_bibfiles.is_empty() { println!( "{}", @@ -81,29 +80,18 @@ impl BibiSetup { ); println!(); println!("{}", cliargs::help_func()); - // panic!("No file passed as argument. Please choose a .bib file.") std::process::exit(1) } else { + // Loop over all files and check for the correct extension main_bibfiles.iter().for_each(|f| if f.extension().is_some() && f.extension().unwrap() != "bib" { panic!("File \'{}\' has no valid extension. Please select a file with \'.bib\' extension", f.to_str().unwrap()) }); } - - Ok(()) } fn bibfiles_to_string(main_bibfiles: &[PathBuf]) -> String { - // let file_strings = String::new(); - - // for f in main_bibfiles { - // file_strings. - // } - - // main_bibfiles - // .iter() - // .for_each(|f| format!("{}\n{}", file_strings, fs::read_to_string(f).unwrap())); - - // file_strings + // Map PathBufs to String anc join the vector into one big string + // This behaviour is needed by the biblatex crate for parsing let file_strings: Vec<String> = main_bibfiles .iter() .map(|f| fs::read_to_string(f).unwrap()) |
