// SPDX-FileCopyrightText: 2025 - 2026 Frederic Ruget <fred@atlant.is> (GitHub: @douzebis)
//
// SPDX-License-Identifier: MIT
use anyhow::Result;
use clap::Args;
use yb_core::{
errors::{explain_pcsc, PcscCode},
open_backend,
};
#[derive(Args, Debug)]
pub struct ListReadersArgs {}
/// Run list-readers without constructing a Context (works when no YubiKey is connected).
pub fn run(_args: &ListReadersArgs) -> Result<()> {
let readers = open_backend()?.list_readers()?;
if readers.is_empty() {
// Same explanation as "no YubiKey found" elsewhere (spec 0025 ยง4);
// still exit 0, as before.
eprintln!("No PC/SC readers found.");
if let Some(fix) = explain_pcsc(&PcscCode::NoReaders).and_then(|e| e.fix) {
eprintln!(" Try: {fix}.");
}
} else {
for r in &readers {
println!("{r}");
}
}
Ok(())
}