aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/bibiman.rs12
-rw-r--r--src/bibiman/bibisetup.rs15
-rw-r--r--src/cliargs.rs56
-rw-r--r--src/tui/ui.rs13
-rw-r--r--tests/multi-files/bibfile1.bib2
-rw-r--r--tests/multi-files/wrong-ext.txt0
8 files changed, 64 insertions, 38 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3609d77..7d543d2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -71,7 +71,7 @@ dependencies = [
[[package]]
name = "bibiman"
-version = "0.7.0"
+version = "0.8.0"
dependencies = [
"arboard",
"biblatex",
diff --git a/Cargo.toml b/Cargo.toml
index ccec50b..768dbdf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bibiman"
-version = "0.7.0"
+version = "0.8.0"
authors = ["lukeflo <lukeflo_git@posteo.de>"]
license = "GPL-3.0-or-later"
repository = "https://codeberg.org/lukeflo/bibiman"
diff --git a/src/bibiman.rs b/src/bibiman.rs
index b8f04c8..bba3eec 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -78,7 +78,7 @@ impl Bibiman {
// Constructs a new instance of [`App`].
pub fn new(args: &CLIArgs) -> Result<Self> {
// let main_bibfiles = args.fileargs.clone();
- let main_biblio = BibiSetup::new(&args.fileargs);
+ let main_biblio = BibiSetup::new(&args.files);
let tag_list = TagList::new(main_biblio.keyword_list.clone());
let search_struct = BibiSearch::default();
let entry_table = EntryTable::new(&main_biblio.entry_list);
@@ -123,7 +123,7 @@ impl Bibiman {
}
pub fn update_lists(&mut self, args: &CLIArgs) {
- self.main_biblio = BibiSetup::new(&args.fileargs);
+ self.main_biblio = BibiSetup::new(&args.files);
self.tag_list = TagList::new(self.main_biblio.keyword_list.clone());
self.entry_table = EntryTable::new(&self.main_biblio.entry_list);
}
@@ -312,17 +312,17 @@ impl Bibiman {
// Check if multiple files were passed to bibiman and
// return the correct file path
- let filepath = if args.fileargs.len() == 1 {
- args.fileargs.first().unwrap().as_os_str()
+ let filepath = if args.files.len() == 1 {
+ args.files.first().unwrap().as_os_str()
} else {
let mut idx = 0;
- for f in &args.fileargs {
+ for f in &args.files {
if search::search_pattern_in_file(&citekey_pattern, &f).is_some() {
break;
}
idx += 1;
}
- args.fileargs[idx].as_os_str()
+ args.files[idx].as_os_str()
};
let filecontent = fs::read_to_string(&filepath).unwrap();
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs
index ad413a4..b0049c6 100644
--- a/src/bibiman/bibisetup.rs
+++ b/src/bibiman/bibisetup.rs
@@ -83,8 +83,19 @@ impl BibiSetup {
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())
+ main_bibfiles.iter().for_each(|f| {
+ if f.extension().is_some() && f.extension().unwrap() != "bib" {
+ println!(
+ "{}\n{}",
+ "The passed file has no valid extension. You need a \'.bib\' file:"
+ .red()
+ .bold(),
+ f.as_os_str().to_string_lossy().bright_red().italic()
+ );
+ println!();
+ println!("{}", cliargs::help_func());
+ std::process::exit(1)
+ }
});
}
}
diff --git a/src/cliargs.rs b/src/cliargs.rs
index 02fc8df..6224b7b 100644
--- a/src/cliargs.rs
+++ b/src/cliargs.rs
@@ -19,7 +19,6 @@ use color_eyre::eyre::Result;
use color_eyre::owo_colors::OwoColorize;
use lexopt::prelude::*;
use std::env;
-use std::ffi::OsString;
use std::path::PathBuf;
use walkdir::WalkDir;
@@ -28,7 +27,8 @@ use walkdir::WalkDir;
pub struct CLIArgs {
pub helparg: bool,
pub versionarg: bool,
- pub fileargs: Vec<PathBuf>,
+ pub pos_args: Vec<PathBuf>,
+ pub files: Vec<PathBuf>,
}
impl CLIArgs {
@@ -40,40 +40,48 @@ impl CLIArgs {
match arg {
Short('h') | Long("help") => args.helparg = true,
Short('v') | Long("version") => args.versionarg = true,
- Value(pos_arg) => parse_files(&mut args, pos_arg),
+ // Value(pos_arg) => parse_files(&mut args, pos_arg),
+ Value(pos_arg) => args.pos_args.push(pos_arg.into()),
_ => return Err(arg.unexpected()),
}
}
+
+ args.files = parse_files(args.pos_args.clone());
+
Ok(args)
}
}
-pub fn parse_files(args: &mut CLIArgs, pos_arg: OsString) {
+fn parse_files(args: Vec<PathBuf>) -> Vec<PathBuf> {
// convert to PathBuf to use methods for testing the path
- let path = PathBuf::from(pos_arg);
+ // let path = PathBuf::from(pos_arg);
+ let mut files: Vec<PathBuf> = Vec::new();
// If pos arg is file, just push it to path vec
- if path.is_file() {
- args.fileargs.push(path);
- // If pos arg is dir, walk dir and collect bibfiles
- } else if path.is_dir() {
- for file in WalkDir::new(path) {
- let f = file.unwrap().into_path();
- if f.is_file() && f.extension().unwrap() == "bib" {
- args.fileargs.push(f)
+ for i in args {
+ if i.is_file() {
+ files.push(i);
+ // If pos arg is dir, walk dir and collect bibfiles
+ } else if i.is_dir() {
+ for file in WalkDir::new(i) {
+ let f = file.unwrap().into_path();
+ if f.is_file() && f.extension().unwrap_or_default() == "bib" {
+ files.push(f)
+ }
}
+ } else {
+ println!(
+ "{}\n{}",
+ "The positional argument is neither a valid file, nor a directory:"
+ .red()
+ .bold(),
+ i.as_os_str().to_string_lossy().bright_red().italic()
+ );
+ println!();
+ println!("{}", help_func());
+ std::process::exit(1)
}
- } else {
- println!(
- "{}\n{}",
- "The positional argument is neither a valid file, nor a directory:"
- .red()
- .bold(),
- path.as_os_str().to_string_lossy().bright_red().italic()
- );
- println!();
- println!("{}", help_func());
- std::process::exit(1)
}
+ files
}
pub fn help_func() -> String {
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index ddb9080..45dfbcc 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -367,16 +367,23 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect:
.horizontal_margin(1)
.areas(rect);
- let file_info = if args.fileargs.len() == 1 {
+ let file_info = if args.pos_args.len() == 1 && args.pos_args.first().unwrap().is_file() {
Line::from(vec![
Span::raw("File: ").bold(),
- Span::raw(args.fileargs[0].file_name().unwrap().to_string_lossy()).bold(),
+ Span::raw(args.pos_args[0].file_name().unwrap().to_string_lossy()).bold(),
+ ])
+ .bg(HEADER_FOOTER_BG)
+ } else if args.pos_args.len() == 1 && args.pos_args.first().unwrap().is_dir() {
+ Line::from(vec![
+ Span::raw("Directory: ").bold(),
+ Span::raw(args.pos_args[0].file_name().unwrap().to_string_lossy()).bold(),
+ Span::raw("/*.bib").bold(),
])
.bg(HEADER_FOOTER_BG)
} else {
Line::from(vec![
Span::raw("Multiple files (").bold(),
- Span::raw(count_files(&args.fileargs).to_string()).bold(),
+ Span::raw(count_files(&args.files).to_string()).bold(),
Span::raw(")"),
])
.bg(HEADER_FOOTER_BG)
diff --git a/tests/multi-files/bibfile1.bib b/tests/multi-files/bibfile1.bib
index 209b968..8f245b8 100644
--- a/tests/multi-files/bibfile1.bib
+++ b/tests/multi-files/bibfile1.bib
@@ -6,7 +6,7 @@
volume = {61},
pages = {204--208},
editor = {Matuz, Roger and Miller, Helen},
- keywords = {narration},
+ keywords = {narration, critic},
langid = {english},
langidopts = {variant=american},
annotation = {A \texttt{collection} entry providing the excerpt information for the \texttt{doody} entry. Note the format of the \texttt{pages} field},
diff --git a/tests/multi-files/wrong-ext.txt b/tests/multi-files/wrong-ext.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/multi-files/wrong-ext.txt