diff --git a/cli/src/main.rs b/cli/src/main.rs index e545b72..69ed0a3 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -10,6 +10,7 @@ use regex::Captures; use regex::Regex; use reqwest::Url; use serde_json::json; +use std::collections::HashMap; use std::net::SocketAddr; use std::path::Path; use std::path::PathBuf; @@ -196,16 +197,34 @@ fn main() -> Result<()> { let client = reqwest::blocking::Client::new(); let response = client.post(api_url).body(query).send()?; - match response.error_for_status_ref() { - Ok(_) => match format { - OutputFormat::Json | OutputFormat::Raw => Ok(println!("{}", response.text()?)), - OutputFormat::Tsv => todo!(), - }, - Err(err) => { - error!("{}", response.text()?); - Err(err.into()) + response.error_for_status_ref()?; + + match format { + OutputFormat::Json | OutputFormat::Raw => println!("{}", response.text()?), + OutputFormat::Tsv => { + eprintln!( + "entity\tattribute\tvalue\ttimestamp\tprovenance" + ); + response + .json::>()? + .iter() + .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(), + ) + }) } } + + Ok(()) } Commands::Insert { url,