From d260c0fbcb3fd9c4f7c83af3f1e4fdd441c3d67d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 10 Feb 2021 22:06:47 -0800 Subject: several bugfixes --- fatcat-cli/src/api.rs | 5 ++++- fatcat-cli/src/commands.rs | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fatcat-cli/src/api.rs b/fatcat-cli/src/api.rs index 2463aab..37e8a51 100644 --- a/fatcat-cli/src/api.rs +++ b/fatcat-cli/src/api.rs @@ -412,7 +412,10 @@ impl FatcatApiClient { extra.insert( "agent".to_string(), serde_json::Value::String("fatcat-cli".to_string()), - // TODO: version? + ); + extra.insert( + "agent_version".to_string(), + serde_json::Value::String(env!("CARGO_PKG_VERSION").to_string()), ); extra }); diff --git a/fatcat-cli/src/commands.rs b/fatcat-cli/src/commands.rs index 1a2d33b..32bfea2 100644 --- a/fatcat-cli/src/commands.rs +++ b/fatcat-cli/src/commands.rs @@ -176,7 +176,7 @@ pub fn print_editgroups(eg_list: Vec, json: bool) -> Result<( for eg in eg_list { writeln!( tw, - "{}\t{}\t{}\t{}\t{}", + "editgroup_{}\t{}\t{}\t{}\t{}", eg.editgroup_id.unwrap(), eg.changelog_index .map_or("-".to_string(), |v| v.to_string()), @@ -292,7 +292,7 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) SearchEntityType::File => { writeln!( tw, - "ident\tsha1\tsize\tmimetype" + "ident\tsha1\tsize_bytes\tmimetype" )?; } } @@ -314,7 +314,7 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) SearchEntityType::Container => { writeln!( tw, - "release_{}\t{}\t{}", + "container_{}\t{}\t{}", hit["ident"].as_str().unwrap_or("-"), hit["issnl"].as_str().unwrap_or("-"), hit["name"].as_str().unwrap_or("-"), @@ -323,10 +323,10 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType) SearchEntityType::File => { writeln!( tw, - "release_{}\t{}\t{}\t{}", + "file_{}\t{}\t{}\t{}", hit["ident"].as_str().unwrap_or("-"), hit["sha1"].as_str().unwrap_or("-"), - hit["size"].as_u64().map_or("-".to_string(), |v| v.to_string()), + hit["size_bytes"].as_u64().map_or("-".to_string(), |v| v.to_string()), hit["mimetype"].as_str().unwrap_or("-"), )?; } @@ -498,7 +498,7 @@ impl BatchGrouper { mutations: Vec, ) -> Result { let obj: serde_json::Value = serde_json::from_str(json_str)?; - let ident = obj["ident"].as_str().unwrap(); // TODO: safer extraction of this ident? + let ident = obj["ident"].as_str().ok_or(anyhow!("expect entity JSON to have 'ident' field"))?; let editgroup_id = self.increment_editgroup(api_client)?; let mut entity = entity_model_from_json_str(self.entity_type, &json_str)?; entity.mutate(mutations)?; @@ -515,7 +515,7 @@ impl BatchGrouper { json_str: &str, ) -> Result { let obj: serde_json::Value = serde_json::from_str(json_str)?; - let ident = obj["ident"].as_str().unwrap(); // TODO: safer extraction of this ident? + let ident = obj["ident"].as_str().ok_or(anyhow!("expect entity JSON to have 'ident' field"))?; let editgroup_id = self.increment_editgroup(api_client)?; api_client.delete_entity( Specifier::from_ident(self.entity_type, ident.to_string()), @@ -540,9 +540,14 @@ impl BatchGrouper { if self.current_count > 0 && self.current_editgroup_id.is_some() { let eg_id = self.current_editgroup_id.clone().unwrap(); if self.auto_accept { - api_client.accept_editgroup(eg_id)?; + api_client.accept_editgroup(eg_id.clone())?; + // This doesn't return changelog entry, so just printing editgroup_id + //writeln!(&mut std::io::stdout(), "{}", entry.to_json_string()?)?; + println!("editgroup_{}", eg_id); } else { - api_client.update_editgroup_submit(eg_id, true)?; + let _eg = api_client.update_editgroup_submit(eg_id.clone(), true)?; + //writeln!(&mut std::io::stdout(), "{}", eg.to_json_string()?)?; + println!("editgroup_{}", eg_id); } self.total_count += self.current_count; self.current_count = 0; -- cgit v1.2.3