feat: support --json

This commit is contained in:
2021-07-05 00:15:18 +08:00
parent c053c53fbb
commit 1e7be5bc9f
2 changed files with 51 additions and 10 deletions

View File

@@ -21,12 +21,15 @@ impl Command for CommandImpl {
}
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 app_id = sub_arg_matches.value_of("app-id").unwrap();
let timeout_ms = match sub_arg_matches.value_of("timeout").unwrap().parse::<u32>() {
Ok(t) => (t * 1000) as u64,
Err(e) => return simple_error!("Timeout should be a number: {}", e),
};
let json_output = sub_arg_matches.is_present("json");
let u2fv2_challenge = U2fV2Challenge::new_random(app_id);
let u2fv2_challenge_str = u2fv2_challenge.to_json();
@@ -65,7 +68,7 @@ impl Command for CommandImpl {
match u2f_registration_data {
Ok(data) => {
if json_output {
success!("{}", serde_json::to_string_pretty(&data).unwrap());
println!("{}", serde_json::to_string_pretty(&data).unwrap());
} else {
success!("Device info: {}", data.device_info);
if let Some(cert) = data.attestation_cert_pem {