aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorlukeflo2024-10-05 22:37:02 +0200
committerlukeflo2024-10-05 22:37:02 +0200
commiteeb8f1b39d965157ed3ea5f7bffae421cce435b3 (patch)
tree89838d867f2ceb6f436e4a051054b6609c6f230b /src/backend
parent6717d6a9087180754eda66f89b348ce62b313e1e (diff)
downloadbibiman-eeb8f1b39d965157ed3ea5f7bffae421cce435b3.tar.gz
bibiman-eeb8f1b39d965157ed3ea5f7bffae421cce435b3.zip
reordering src structure, cli args struct
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/bib.rs5
-rw-r--r--src/backend/cliargs.rs46
2 files changed, 29 insertions, 22 deletions
diff --git a/src/backend/bib.rs b/src/backend/bib.rs
index c897099..ba752a7 100644
--- a/src/backend/bib.rs
+++ b/src/backend/bib.rs
@@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
-use super::cliargs::PosArgs;
use std::{fs, path::PathBuf};
use biblatex::{self, Bibliography};
@@ -33,9 +32,9 @@ pub struct BibiMain {
}
impl BibiMain {
- pub fn new() -> Self {
+ pub fn new(main_bibfile: PathBuf) -> Self {
// TODO: Needs check for config file path as soon as config file is impl
- let bibfile = PosArgs::parse_pos_args().bibfilearg;
+ let bibfile = main_bibfile;
let bibfilestring = fs::read_to_string(&bibfile).unwrap();
let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap();
let citekeys = Self::get_citekeys(&bibliography);
diff --git a/src/backend/cliargs.rs b/src/backend/cliargs.rs
index 516de66..31d37f0 100644
--- a/src/backend/cliargs.rs
+++ b/src/backend/cliargs.rs
@@ -27,7 +27,7 @@ sarge! {
// Show help and exit.
'h' help: bool,
- // Show version and exit. TODO: Write version...
+ // Show version and exit.
'v' version: bool,
}
@@ -35,37 +35,45 @@ sarge! {
pub struct CLIArgs {
pub helparg: bool,
pub versionarg: bool,
+ pub bibfilearg: PathBuf,
}
impl CLIArgs {
- pub fn parse_cli_args() -> Self {
- let (cli_args, _) = ArgumentsCLI::parse().expect("Could not parse CLI arguments");
+ pub fn new() -> Self {
+ let (cli_args, pos_args) = ArgumentsCLI::parse().expect("Could not parse CLI arguments");
+ let bibfilearg = if pos_args.len() > 1 {
+ PathBuf::from(&pos_args[1])
+ // pos_args[1].to_string()
+ } else {
+ panic!("No path to bibfile provided as argument")
+ };
Self {
helparg: cli_args.help,
versionarg: cli_args.version,
+ bibfilearg,
}
}
}
// Struct for positional arguments
// TODO: Can surely be improved!!
-pub struct PosArgs {
- pub bibfilearg: PathBuf,
-}
+// pub struct PosArgs {
+// pub bibfilearg: PathBuf,
+// }
-impl PosArgs {
- pub fn parse_pos_args() -> Self {
- let (_, pos_args) = ArgumentsCLI::parse().expect("Could not parse positional arguments");
- Self {
- bibfilearg: if pos_args.len() > 1 {
- PathBuf::from(&pos_args[1])
- // pos_args[1].to_string()
- } else {
- panic!("No path to bibfile provided as argument")
- }, // bibfilearg: pos_args[1].to_string(),
- }
- }
-}
+// impl PosArgs {
+// pub fn parse_pos_args() -> Self {
+// let (_, pos_args) = ArgumentsCLI::parse().expect("Could not parse positional arguments");
+// Self {
+// bibfilearg: if pos_args.len() > 1 {
+// PathBuf::from(&pos_args[1])
+// // pos_args[1].to_string()
+// } else {
+// panic!("No path to bibfile provided as argument")
+// }, // bibfilearg: pos_args[1].to_string(),
+// }
+// }
+// }
pub fn help_func() -> String {
let help = format!(