From 13cfffbcbd1c04256e204887f9d7c9e3b84568a3 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Tue, 1 Aug 2023 22:51:42 +0200 Subject: [PATCH] refactor: move cli args to util module --- src/main.rs | 24 +++--------------------- src/util.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 src/util.rs diff --git a/src/main.rs b/src/main.rs index e73f55f..7399644 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,27 +2,9 @@ use std::env; use gumdrop::Options; use anyhow::Result; +mod util; mod bwutil; -/// Represents command-line parameters. -#[derive(Debug, Options)] -struct Cli { - #[options(help = "print help message and exit")] - help: bool, - #[options(help = "show debug output")] - debug: bool, - #[options(help = "folder name to use to search for SSH keys", default = "ssh-agent")] - folder: String, - #[options(help = "custom field name where the private key is stored", meta = "PRIVATE_KEY", default = "private-key")] - key: String, - #[options(help = "custom field name where the key passphrase is stored", meta = "PASS", default = "passphrase")] - passphrase: String, - #[options(help = "session to use to log in to bitwarden-cli")] - session: String, - #[options(help = "print version and exit")] - version: bool, -} - /// Environment variable housing an existing Bitwarden session. const SESSION_ENV_KEY: &str = "BW_SESSION"; /// Environment variable referencing the name of the field containing the SSH key filename. @@ -31,7 +13,7 @@ const BW_FIELD_KEY_FILENAME: &str = "private"; const BW_FIELD_KEY_PASSPHRASE: &str = "passphrase"; fn main() -> Result<()> { - let args: Cli = Cli::parse_args_default_or_exit(); + let args: util::Cli = util::Cli::parse_args_default_or_exit(); if args.version { let name = env!("CARGO_PKG_NAME"); let version = env!("CARGO_PKG_VERSION"); @@ -85,7 +67,7 @@ fn main() -> Result<()> { /// 3. Check for login status from `bw` /// 4. Login or unlock based on login status and use that. /// An invalid `BW_SESSION` or `--session` will prompt a login. -fn check_session_token(args: &Cli) -> Result { +fn check_session_token(args: &util::Cli) -> Result { println!("Getting Bitwarden session..."); let mut session_token: String = String::new(); // Get session flag from the user diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..5088998 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,20 @@ +use gumdrop::Options; + +/// Represents command-line parameters. +#[derive(Debug, Options)] +pub struct Cli { + #[options(help = "print help message and exit")] + pub help: bool, + #[options(help = "show debug output")] + pub debug: bool, + #[options(help = "folder name to use to search for SSH keys", default = "ssh-agent")] + pub folder: String, + #[options(help = "custom field name where the private key is stored", meta = "PRIVATE_KEY", default = "private-key")] + pub key: String, + #[options(help = "custom field name where the key passphrase is stored", meta = "PASS", default = "passphrase")] + pub passphrase: String, + #[options(help = "session to use to log in to bitwarden-cli")] + pub session: String, + #[options(help = "print version and exit")] + pub version: bool, +} -- libgit2 1.7.2