use abscissa::Callable;
mod detect;
mod help;
mod keys;
mod test;
pub use self::{detect::DetectCommand, help::HelpCommand, keys::KeysCommand, test::TestCommand};
#[derive(Debug, Options)]
pub enum YubihsmCommand {
#[options(help = "detect all YubiHSM2 devices connected via USB")]
Detect(DetectCommand),
#[options(help = "show help for the 'yubihsm' subcommand")]
Help(HelpCommand),
#[options(help = "key management subcommands")]
Keys(KeysCommand),
#[options(help = "perform a signing test")]
Test(TestCommand),
}
impl_command!(YubihsmCommand);
impl Callable for YubihsmCommand {
fn call(&self) {
match self {
YubihsmCommand::Detect(detect) => detect.call(),
YubihsmCommand::Help(help) => help.call(),
YubihsmCommand::Keys(keys) => keys.call(),
YubihsmCommand::Test(test) => test.call(),
}
}
}
impl YubihsmCommand {
pub(super) fn config_path(&self) -> Option<&str> {
match self {
YubihsmCommand::Detect(detect) => detect.config.as_ref().map(|s| s.as_ref()),
YubihsmCommand::Keys(keys) => keys.config_path(),
_ => None,
}
}
pub(super) fn verbose(&self) -> bool {
match self {
YubihsmCommand::Detect(detect) => detect.verbose,
YubihsmCommand::Test(test) => test.verbose,
_ => false,
}
}
}