From 259947386a6f348bf249ff511e3bc73584483956 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 31 Dec 2020 22:59:02 +0000 Subject: [PATCH] Add skeleton of administration commands --- src/error.rs | 5 +++++ src/main.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/error.rs b/src/error.rs index d33513a..7875b13 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ use std::io; pub enum Error { Io(io::Error), + MultipleCommands, } impl From for Error { @@ -17,6 +18,10 @@ impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::Io(e) => writeln!(f, "Failed to set up YubiKey: {}", e)?, + Error::MultipleCommands => writeln!( + f, + "Only one of --generate, --identity, --list, --list-all can be specified." + )?, } writeln!(f)?; writeln!( diff --git a/src/main.rs b/src/main.rs index 832b011..9df723b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,11 +17,32 @@ struct PluginOptions { no_short )] age_plugin: Option, + + #[options(help = "Generate a new YubiKey identity.")] + generate: bool, + + #[options(help = "Print the identity stored in a YubiKey slot.")] + identity: bool, + + #[options(help = "List all age identities in connected YubiKeys.")] + list: bool, + + #[options(help = "List all YubiKey keys that are compatible with age.", no_short)] + list_all: bool, } fn main() -> Result<(), Error> { let opts = PluginOptions::parse_args_default_or_exit(); + if [opts.generate, opts.identity, opts.list, opts.list_all] + .iter() + .filter(|&&b| b) + .count() + > 1 + { + return Err(Error::MultipleCommands); + } + if let Some(state_machine) = opts.age_plugin { run_state_machine( &state_machine, @@ -29,6 +50,14 @@ fn main() -> Result<(), Error> { || plugin::IdentityPlugin::default(), )?; Ok(()) + } else if opts.generate { + todo!() + } else if opts.identity { + todo!() + } else if opts.list { + todo!() + } else if opts.list_all { + todo!() } else { // TODO: CLI identity generation Ok(())