From 37e9ccec5624e8acd5e128fdb2b61b9c7a051b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Tue, 6 Jun 2023 20:23:20 +0200 Subject: [PATCH] chore(cli): gracefull failback if API format changes --- cli/src/main.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 561eef9..b66bafe 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -545,11 +545,27 @@ async fn print_response_entries(response: reqwest::Response, format: OutputForma entries.for_each(|(_, entry)| { println!( "{}\t{}\t{}\t{}\t{}", - entry.get("entity").and_then(|e| e.as_str()).unwrap(), - entry.get("attribute").and_then(|a| a.as_str()).unwrap(), - entry.get("value").and_then(|v| v.get("c")).unwrap(), - entry.get("timestamp").and_then(|t| t.as_str()).unwrap(), - entry.get("provenance").and_then(|p| p.as_str()).unwrap(), + entry + .get("entity") + .and_then(|e| e.as_str()) + .unwrap_or("???"), + entry + .get("attribute") + .and_then(|a| a.as_str()) + .unwrap_or("???"), + entry + .get("value") + .and_then(|v| v.get("c")) + .map(|c| format!("{c}")) + .unwrap_or("???".to_string()), + entry + .get("timestamp") + .and_then(|t| t.as_str()) + .unwrap_or("???"), + entry + .get("provenance") + .and_then(|p| p.as_str()) + .unwrap_or("???"), ) }) }