index : bitwarden-ssh-agent.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-08-01 20:54:22.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-08-01 20:54:22.0 +00:00:00
commit
83f70ae1ec1048f145a831343adb2a10c0d58959 [patch]
tree
b569e5e72579f6f0d1afd4ec53a8dda94a909da2
parent
13cfffbcbd1c04256e204887f9d7c9e3b84568a3
download
83f70ae1ec1048f145a831343adb2a10c0d58959.tar.gz

refactor: extract version info code to a function in `util`



Diff

 src/main.rs |  4 +---
 src/util.rs |  9 +++++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 7399644..4fc1059 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,9 +15,7 @@ const BW_FIELD_KEY_PASSPHRASE: &str = "passphrase";
fn main() -> Result<()> {
    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");
		println!("{} {}", name, version);
		println!("{}", &util::get_version_string()?);
		return Ok(());
	}

diff --git a/src/util.rs b/src/util.rs
index 5088998..9421fed 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,3 +1,5 @@
use std::env;
use anyhow::Result;
use gumdrop::Options;

/// Represents command-line parameters.
@@ -18,3 +20,10 @@ pub struct Cli {
	#[options(help = "print version and exit")]
    pub version: bool,
}

/// Retrieves the version information in the form of `PKG_NAME` - `PKG_VERSION`.
pub fn get_version_string() -> Result<String> {
	let name = env!("CARGO_PKG_NAME");
	let version = env!("CARGO_PKG_VERSION");
	return Ok(format!("{} {}", name, version))
}
\ No newline at end of file