From 80fbab0f4dcdd6e172fab00794fb943bbe81fa1e Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 8 Sep 2020 19:18:13 +0200 Subject: Use DeviceModel::as_user_facing_str in status This match replaces the model names in the status command with calls to the DeviceModel::as_user_facing_str method. --- src/args.rs | 9 +++++++++ src/commands.rs | 16 +++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/args.rs b/src/args.rs index 80abe17..ab46ee7 100644 --- a/src/args.rs +++ b/src/args.rs @@ -50,6 +50,15 @@ impl DeviceModel { } } +impl From for DeviceModel { + fn from(model: nitrokey::Model) -> DeviceModel { + match model { + nitrokey::Model::Pro => DeviceModel::Pro, + nitrokey::Model::Storage => DeviceModel::Storage, + } + } +} + impl From for nitrokey::Model { fn from(model: DeviceModel) -> nitrokey::Model { match model { diff --git a/src/commands.rs b/src/commands.rs index ebb28ca..23f43f3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -364,11 +364,7 @@ fn print_storage_status( } /// Query and pretty print the status that is common to all Nitrokey devices. -fn print_status( - ctx: &mut Context<'_>, - model: &'static str, - device: &nitrokey::DeviceWrapper<'_>, -) -> anyhow::Result<()> { +fn print_status(ctx: &mut Context<'_>, device: &nitrokey::DeviceWrapper<'_>) -> anyhow::Result<()> { let serial_number = device .get_serial_number() .context("Could not query the serial number")?; @@ -381,7 +377,7 @@ fn print_status( firmware version: {fwv} user retry count: {urc} admin retry count: {arc}"#, - model = model, + model = args::DeviceModel::from(device.get_model()).as_user_facing_str(), id = serial_number, fwv = device .get_firmware_version() @@ -407,13 +403,7 @@ fn print_status( /// Inquire the status of the nitrokey. pub fn status(ctx: &mut Context<'_>) -> anyhow::Result<()> { - with_device(ctx, |ctx, device| { - let model = match device { - nitrokey::DeviceWrapper::Pro(_) => "Pro", - nitrokey::DeviceWrapper::Storage(_) => "Storage", - }; - print_status(ctx, model, &device) - }) + with_device(ctx, |ctx, device| print_status(ctx, &device)) } /// List the attached Nitrokey devices. -- cgit v1.2.1