diff --git a/src/error.rs b/src/error.rs index d0c535d..05d0ffb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,8 @@ use crate::util::slot_to_ui; pub enum Error { CustomManagementKey, + InvalidFlagCommand(String, String), + InvalidFlagTui(String), InvalidPinLength, InvalidPinPolicy(String), InvalidSlot(u8), @@ -42,6 +44,14 @@ impl fmt::Debug for Error { Error::CustomManagementKey => { writeln!(f, "Custom unprotected management keys are not supported.")? } + Error::InvalidFlagCommand(flag, command) => { + writeln!(f, "Flag '{}' cannot be used with '{}'.", flag, command)? + } + Error::InvalidFlagTui(flag) => writeln!( + f, + "Flag '{}' cannot be used with the interactive interface.", + flag + )?, Error::InvalidPinLength => writeln!(f, "The PIN needs to be 1-8 characters.")?, Error::InvalidPinPolicy(s) => writeln!( f, diff --git a/src/main.rs b/src/main.rs index ef320e4..d2ed3be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,6 +267,12 @@ fn print_details( } fn identity(flags: PluginFlags) -> Result<(), Error> { + if flags.force { + return Err(Error::InvalidFlagCommand( + "--force".into(), + "--identity".into(), + )); + } print_details("identities", flags, false, util::print_identity) } @@ -274,6 +280,12 @@ fn list(flags: PluginFlags, all: bool) -> Result<(), Error> { if all && flags.slot.is_some() { return Err(Error::UseListForSingleSlot); } + if flags.force { + return Err(Error::InvalidFlagCommand( + "--force".into(), + format!("--list{}", if all { "-all" } else { "" }), + )); + } print_details("recipients", flags, all, |_, recipient, metadata| { println!("{}", metadata); @@ -318,6 +330,9 @@ fn main() -> Result<(), Error> { } else if opts.list_all { list(opts.try_into()?, true) } else { + if opts.force { + return Err(Error::InvalidFlagTui("--force".into())); + } let flags: PluginFlags = opts.try_into()?; eprintln!("✨ Let's get your YubiKey set up for age! ✨"); @@ -511,7 +526,6 @@ fn main() -> Result<(), Error> { }) .with_pin_policy(Some(pin_policy)) .with_touch_policy(Some(touch_policy)) - .force(flags.force) .build(&mut yubikey)?, true, )