Add skeleton of administration commands

This commit is contained in:
Jack Grigg
2020-12-31 22:59:02 +00:00
parent 0052d91aad
commit 259947386a
2 changed files with 34 additions and 0 deletions
+5
View File
@@ -3,6 +3,7 @@ use std::io;
pub enum Error { pub enum Error {
Io(io::Error), Io(io::Error),
MultipleCommands,
} }
impl From<io::Error> for Error { impl From<io::Error> for Error {
@@ -17,6 +18,10 @@ impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Error::Io(e) => writeln!(f, "Failed to set up YubiKey: {}", e)?, 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!(f)?;
writeln!( writeln!(
+29
View File
@@ -17,11 +17,32 @@ struct PluginOptions {
no_short no_short
)] )]
age_plugin: Option<String>, age_plugin: Option<String>,
#[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> { fn main() -> Result<(), Error> {
let opts = PluginOptions::parse_args_default_or_exit(); 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 { if let Some(state_machine) = opts.age_plugin {
run_state_machine( run_state_machine(
&state_machine, &state_machine,
@@ -29,6 +50,14 @@ fn main() -> Result<(), Error> {
|| plugin::IdentityPlugin::default(), || plugin::IdentityPlugin::default(),
)?; )?;
Ok(()) Ok(())
} else if opts.generate {
todo!()
} else if opts.identity {
todo!()
} else if opts.list {
todo!()
} else if opts.list_all {
todo!()
} else { } else {
// TODO: CLI identity generation // TODO: CLI identity generation
Ok(()) Ok(())