aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-08 19:18:13 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-09-09 21:55:12 +0200
commit80fbab0f4dcdd6e172fab00794fb943bbe81fa1e (patch)
treec8d2ca743596d7b3d38aaf7521c60add81199b3c /src
parent663f24b2e41c90709750337e47f2f43b3100422f (diff)
downloadnitrocli-80fbab0f4dcdd6e172fab00794fb943bbe81fa1e.tar.gz
nitrocli-80fbab0f4dcdd6e172fab00794fb943bbe81fa1e.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/args.rs9
-rw-r--r--src/commands.rs16
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<nitrokey::Model> for DeviceModel {
+ fn from(model: nitrokey::Model) -> DeviceModel {
+ match model {
+ nitrokey::Model::Pro => DeviceModel::Pro,
+ nitrokey::Model::Storage => DeviceModel::Storage,
+ }
+ }
+}
+
impl From<DeviceModel> 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.