feat: update crates

This commit is contained in:
2023-03-14 08:58:05 +08:00
parent 19c84448fb
commit 6437b955d7
10 changed files with 258 additions and 176 deletions

38
src/cmd_list.rs Normal file
View File

@@ -0,0 +1,38 @@
use std::collections::BTreeMap;
use clap::{App, Arg, ArgMatches, SubCommand};
use rust_util::util_clap::{Command, CommandError};
use yubikey::YubiKey;
pub struct CommandImpl;
impl Command for CommandImpl {
fn name(&self) -> &str { "list" }
fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("YubiKey list")
.arg(Arg::with_name("json").long("json").help("JSON output"))
}
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let json_output = sub_arg_matches.is_present("json");
if json_output { rust_util::util_msg::set_logger_std_out(false); }
let yk = opt_result!(YubiKey::open(), "YubiKey not found: {}");
if json_output {
let mut json = BTreeMap::<&'_ str, String>::new();
json.insert("name", yk.name().to_string());
json.insert("version", yk.version().to_string());
json.insert("serial", yk.serial().0.to_string());
println!("{}", serde_json::to_string_pretty(&json).expect("Convert to JSON failed!"));
} else {
success!("Name: {}", yk.name());
success!("Version: {}", yk.version());
success!("Serial: {}", yk.serial().0);
}
Ok(None)
}
}