From 80ce422a7c9fa0fc6578a44f670bb7d7eb13c560 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Sun, 3 Dec 2023 12:56:55 +0100 Subject: [PATCH 1/2] add SUDO_USER as default --- pin-gen/Cargo.toml | 2 +- pin-gen/src/cli.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pin-gen/Cargo.toml b/pin-gen/Cargo.toml index 6617fd6..bf3c47f 100644 --- a/pin-gen/Cargo.toml +++ b/pin-gen/Cargo.toml @@ -16,7 +16,7 @@ sysexits = "0.7" argon2 = { version = "0.5", features = ["std"] } rand_core = { version = "0.6", features = ["std"] } rpassword = "7.2" -clap = { version = "3.2", features = ["derive"] } +clap = { version = "3.2", features = ["derive", "env"] } birdcage = { version = "0.3", optional = true } [features] diff --git a/pin-gen/src/cli.rs b/pin-gen/src/cli.rs index 5e3794f..a796bb3 100644 --- a/pin-gen/src/cli.rs +++ b/pin-gen/src/cli.rs @@ -8,7 +8,7 @@ use std::path::PathBuf; pub struct CliArgs { #[clap(short = 'f', long, default_value = "/etc/security/pins.toml")] pub database_filepath: PathBuf, - #[clap()] + #[clap(env = "SUDO_USER")] pub username: Option, /// Use this flag to try different parameters. /// It disables the need for a username and pin. From 8323f3ca29511e9a927d27f33a0cce5038a75a81 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Sun, 3 Dec 2023 15:40:00 +0100 Subject: [PATCH 2/2] add value hints --- pin-gen/src/cli.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pin-gen/src/cli.rs b/pin-gen/src/cli.rs index a796bb3..079c94b 100644 --- a/pin-gen/src/cli.rs +++ b/pin-gen/src/cli.rs @@ -1,14 +1,19 @@ use crate::{Error, Result}; -use clap::Parser; +use clap::{Parser, ValueHint}; use error_stack::ResultExt; use std::path::PathBuf; #[derive(Parser, Debug, Clone)] #[clap(author, version, about)] pub struct CliArgs { - #[clap(short = 'f', long, default_value = "/etc/security/pins.toml")] + #[clap( + short = 'f', + long, + default_value = "/etc/security/pins.toml", + value_hint(ValueHint::FilePath) + )] pub database_filepath: PathBuf, - #[clap(env = "SUDO_USER")] + #[clap(env = "SUDO_USER", value_hint(ValueHint::Username))] pub username: Option, /// Use this flag to try different parameters. /// It disables the need for a username and pin.