index : bitwarden-ssh-agent.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-08-01 20:51:42.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-08-01 20:51:42.0 +00:00:00
commit
13cfffbcbd1c04256e204887f9d7c9e3b84568a3 [patch]
tree
55d169bc330c7b30c9d50ff0d52a28d63804a880
parent
53812b8131b9a8dba7824d398a94eb5b6a9226fa
download
13cfffbcbd1c04256e204887f9d7c9e3b84568a3.tar.gz

refactor: move cli args to util module



Diff

 src/main.rs | 24 +++---------------------
 src/util.rs | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 21 deletions(-)

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<String> {
fn check_session_token(args: &util::Cli) -> Result<String> {
	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,
}