aboutsummaryrefslogtreecommitdiff
path: root/src/cliargs.rs
diff options
context:
space:
mode:
authorlukeflo2024-10-22 21:52:36 +0200
committerlukeflo2024-10-22 21:52:36 +0200
commit66402a9c23e0975a8a3d8c2707b689b9cde98ccf (patch)
treeccba415674b13eadb6739f5a4d0cb53642dc2e62 /src/cliargs.rs
parent0a74206015e764551ec2a0ade8f6853e915b6911 (diff)
downloadbibiman-66402a9c23e0975a8a3d8c2707b689b9cde98ccf.tar.gz
bibiman-66402a9c23e0975a8a3d8c2707b689b9cde98ccf.zip
rearrange code, file and folder structure
Diffstat (limited to 'src/cliargs.rs')
-rw-r--r--src/cliargs.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/cliargs.rs b/src/cliargs.rs
new file mode 100644
index 0000000..d3a4652
--- /dev/null
+++ b/src/cliargs.rs
@@ -0,0 +1,89 @@
+// bibiman - a TUI for managing BibLaTeX databases
+// Copyright (C) 2024 lukeflo
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+/////
+
+use std::path::PathBuf;
+
+use sarge::prelude::*;
+
+sarge! {
+ // Name of the struct
+ ArgumentsCLI,
+
+ // Show help and exit.
+ 'h' help: bool,
+
+ // Show version and exit.
+ 'v' version: bool,
+}
+
+// struct for CLIArgs
+pub struct CLIArgs {
+ pub helparg: bool,
+ pub versionarg: bool,
+ pub bibfilearg: PathBuf,
+}
+
+impl CLIArgs {
+ 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 {
+ PathBuf::new()
+ };
+ Self {
+ helparg: cli_args.help,
+ versionarg: cli_args.version,
+ bibfilearg,
+ }
+ }
+}
+
+pub fn help_func() -> String {
+ let help = format!(
+ "\
+{} {}
+
+USAGE:
+ bibiman [FLAGS] [file]
+
+POSITIONAL ARGS:
+ <file> Path to .bib file
+
+FLAGS:
+ -h, --help Show this help and exit
+ -v, --version Show the version and exit",
+ env!("CARGO_PKG_NAME"),
+ env!("CARGO_PKG_VERSION"),
+ );
+ help
+}
+
+pub fn version_func() -> String {
+ let version = format!(
+ "\
+{} {}
+{}
+{}",
+ env!("CARGO_PKG_NAME"),
+ env!("CARGO_PKG_VERSION"),
+ env!("CARGO_PKG_AUTHORS"),
+ env!("CARGO_PKG_LICENSE")
+ );
+ version
+}