Skip to content

Commit

Permalink
feat: Show features in --version output
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick888 committed Feb 19, 2023
1 parent 8330fca commit 7cf9bc5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{num, str::FromStr};

/// Helper that allows Git and shell scripts to use KeePassXC as credential store
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(author, version, long_version = long_version(), about, long_about = None)]
#[clap(propagate_version = true)]
pub struct MainArgs {
/// Specify configuration JSON file path
Expand Down Expand Up @@ -46,6 +46,30 @@ impl HasEntryFilters for MainArgs {
}
}

fn long_version() -> &'static str {
let version = env!("CARGO_PKG_VERSION");
let mut features = vec![];
if cfg!(feature = "strict-caller") {
features.push("strict-caller".to_owned());
}
if cfg!(feature = "notification") {
features.push("notification".to_owned());
}
if cfg!(feature = "encryption") {
features.push("encryption".to_owned());
}
if cfg!(feature = "yubikey") {
features.push("yubikey".to_owned());
}
if features.is_empty() {
version
} else {
let features = features.join(", ");
let version = format!("{version} ({features})");
Box::leak(Box::new(version)).as_str()
}
}

#[derive(Subcommand)]
pub enum Subcommands {
Get(SubGetArgs),
Expand Down

0 comments on commit 7cf9bc5

Please sign in to comment.