aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/fatcat-cli/src/api.rs14
-rw-r--r--rust/fatcat-cli/src/entities.rs2
-rw-r--r--rust/fatcat-cli/src/main.rs10
-rw-r--r--rust/fatcat-cli/src/search.rs4
-rw-r--r--rust/fatcat-cli/src/specifier.rs28
5 files changed, 29 insertions, 29 deletions
diff --git a/rust/fatcat-cli/src/api.rs b/rust/fatcat-cli/src/api.rs
index d26e6d5..41718ea 100644
--- a/rust/fatcat-cli/src/api.rs
+++ b/rust/fatcat-cli/src/api.rs
@@ -62,12 +62,12 @@ impl<'a> FatcatApiClient<'a> {
fatcat_openapi::AuthCheckResponse::Success(_) => Ok(()),
fatcat_openapi::AuthCheckResponse::Forbidden(err) => Err(anyhow!("Forbidden ({}): {}", err.error, err.message)),
fatcat_openapi::AuthCheckResponse::NotAuthorized{body: err, ..} => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
- resp => return Err(anyhow!("{:?}", resp)).context("auth check failed".to_string()),
+ resp => return Err(anyhow!("{:?}", resp)).context("auth check failed"),
}.context("check auth token")?;
match self.rt.block_on(self.api.get_editor(self.editor_id.as_ref().unwrap().to_string())).context("fetching editor account info")? {
fatcat_openapi::GetEditorResponse::Found(editor) => Some(editor),
fatcat_openapi::GetEditorResponse::NotFound(err) => return Err(anyhow!("Not Found: {}", err.message)),
- resp => return Err(anyhow!("{:?}", resp)).context("editor fetch failed".to_string()),
+ resp => return Err(anyhow!("{:?}", resp)).context("editor fetch failed"),
}
} else {
None
@@ -87,7 +87,7 @@ impl<'a> FatcatApiClient<'a> {
let eg = match result {
fatcat_openapi::GetEditgroupResponse::Found(eg) => eg,
other => return Err(anyhow!("{:?}", other))
- .context(format!("failed to fetch editgroup {}", editgroup_id)),
+ .with_context(|| format!("failed to fetch editgroup {}", editgroup_id)),
};
let result = self.rt.block_on(
self.api.update_editgroup(editgroup_id.clone(), eg, Some(submit))
@@ -95,7 +95,7 @@ impl<'a> FatcatApiClient<'a> {
match result {
fatcat_openapi::UpdateEditgroupResponse::UpdatedEditgroup(eg) => Ok(eg),
other => Err(anyhow!("{:?}", other))
- .context(format!("failed to submit editgroup {}", editgroup_id)),
+ .with_context(|| format!("failed to submit editgroup {}", editgroup_id)),
}
}
@@ -135,7 +135,7 @@ impl<'a> FatcatApiClient<'a> {
Changelog(..) => return Err(anyhow!("mutating this entity type doesn't make sense")),
EditorUsername(..) | ReleaseLookup(..) | ContainerLookup(..) | FileLookup(..) | CreatorLookup(..) =>
return Err(anyhow!("into_entity_specifier() didn't work?")),
- }.context(format!("failed to delete {:?}", specifier))
+ }.with_context(|| format!("failed to delete {:?}", specifier))
}
pub fn create_entity_from_json(&mut self, entity_type: EntityType, json_str: &str, editgroup_id: String) -> Result<models::EntityEdit> {
@@ -182,7 +182,7 @@ impl<'a> FatcatApiClient<'a> {
other => Err(anyhow!("{:?}", other)),
}
},
- }.context(format!("parsing and creating {:?} entity", entity_type))
+ }.with_context(|| format!("parsing and creating {:?} entity", entity_type))
}
pub fn update_entity_from_json(&mut self, specifier: Specifier, json_str: &str, editgroup_id: String) -> Result<models::EntityEdit> {
@@ -221,6 +221,6 @@ impl<'a> FatcatApiClient<'a> {
Changelog(..) => return Err(anyhow!("deleting this entity type doesn't make sense")),
EditorUsername(..) | ReleaseLookup(..) | ContainerLookup(..) | FileLookup(..) | CreatorLookup(..) =>
return Err(anyhow!("into_entity_specifier() didn't work?")),
- }.context(format!("failed to update {:?}", specifier))
+ }.with_context(|| format!("failed to update {:?}", specifier))
}
}
diff --git a/rust/fatcat-cli/src/entities.rs b/rust/fatcat-cli/src/entities.rs
index a417f8e..c606d17 100644
--- a/rust/fatcat-cli/src/entities.rs
+++ b/rust/fatcat-cli/src/entities.rs
@@ -1,6 +1,6 @@
use std::str::FromStr;
-use anyhow::{Result, anyhow, Context};
+use anyhow::{Result, anyhow};
use lazy_static::lazy_static;
use regex::Regex;
use fatcat_openapi::models;
diff --git a/rust/fatcat-cli/src/main.rs b/rust/fatcat-cli/src/main.rs
index 7c5595f..05b003d 100644
--- a/rust/fatcat-cli/src/main.rs
+++ b/rust/fatcat-cli/src/main.rs
@@ -279,7 +279,7 @@ fn run(opt: Opt) -> Result<()> {
l => Some(l as u64),
};
let results = fatcat_cli::crude_search(&opt.search_host, entity_type, limit, terms)
- .context(format!("searching for {:?}", entity_type))?;
+ .with_context(|| format!("searching for {:?}", entity_type))?;
eprintln!("Got {} hits in {}ms", results.count, results.took_ms);
for hit in results {
let hit = hit?;
@@ -296,7 +296,7 @@ fn run(opt: Opt) -> Result<()> {
},
Command::Delete { specifier, editgroup_id } => {
let result = api_client.delete_entity(specifier.clone(), editgroup_id)
- .context(format!("delete entity: {:?}", specifier))?;
+ .with_context(|| format!("delete entity: {:?}", specifier))?;
println!("{}", serde_json::to_string(&result)?);
},
Command::Editgroup { cmd: EditgroupCommand::List { editor_id, limit, json } } => {
@@ -311,7 +311,7 @@ fn run(opt: Opt) -> Result<()> {
fatcat_openapi::GetEditorEditgroupsResponse::Found(eg_list) => {
print_editgroups(eg_list, json)?;
},
- other => return Err(anyhow!("{:?}", other)).context(format!("failed to fetch editgroups for editor_{}", editor_id)),
+ other => return Err(anyhow!("{:?}", other)).with_context(|| format!("failed to fetch editgroups for editor_{}", editor_id)),
}
},
Command::Editgroup { cmd: EditgroupCommand::Reviewable { limit, json } } => {
@@ -322,7 +322,7 @@ fn run(opt: Opt) -> Result<()> {
fatcat_openapi::GetEditgroupsReviewableResponse::Found(eg_list) => {
print_editgroups(eg_list, json)?;
},
- other => return Err(anyhow!("{:?}", other)).context("failed to fetch reviewable editgroups".to_string()),
+ other => return Err(anyhow!("{:?}", other)).context("failed to fetch reviewable editgroups"),
}
},
Command::Editgroup { cmd: EditgroupCommand::Create { description }} => {
@@ -338,7 +338,7 @@ fn run(opt: Opt) -> Result<()> {
match result {
fatcat_openapi::CreateEditgroupResponse::SuccessfullyCreated(eg) =>
println!("{}", serde_json::to_string(&eg)?),
- other => return Err(anyhow!("{:?}", other)).context("failed to create editgroup".to_string()),
+ other => return Err(anyhow!("{:?}", other)).context("failed to create editgroup"),
}
},
Command::Editgroup { cmd: EditgroupCommand::Accept { editgroup_id } } => {
diff --git a/rust/fatcat-cli/src/search.rs b/rust/fatcat-cli/src/search.rs
index 4e3fcbd..d7fbbad 100644
--- a/rust/fatcat-cli/src/search.rs
+++ b/rust/fatcat-cli/src/search.rs
@@ -1,8 +1,8 @@
use serde_json::json;
use std::time::Duration;
-use anyhow::{Result, Context, anyhow};
-use log::{self,info,debug};
+use anyhow::{Result, anyhow};
+use log::{self,info};
use crate::EntityType;
diff --git a/rust/fatcat-cli/src/specifier.rs b/rust/fatcat-cli/src/specifier.rs
index c2834b0..3085345 100644
--- a/rust/fatcat-cli/src/specifier.rs
+++ b/rust/fatcat-cli/src/specifier.rs
@@ -78,7 +78,7 @@ impl Specifier {
fatcat_openapi::GetReleaseResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetReleaseResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetReleaseResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
ReleaseLookup(ext_id, key) => {
use ReleaseLookupKey::*;
@@ -95,7 +95,7 @@ impl Specifier {
fatcat_openapi::LookupReleaseResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::LookupReleaseResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::LookupReleaseResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
}
},
Work(fcid) =>
@@ -103,14 +103,14 @@ impl Specifier {
fatcat_openapi::GetWorkResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetWorkResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetWorkResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
Container(fcid) =>
match api_client.rt.block_on(api_client.api.get_container(fcid.to_string(), expand, hide))? {
fatcat_openapi::GetContainerResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetContainerResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetContainerResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
ContainerLookup(ext_id, key) => {
let result = api_client.rt.block_on(match ext_id {
@@ -120,7 +120,7 @@ impl Specifier {
fatcat_openapi::LookupContainerResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::LookupContainerResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::LookupContainerResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
}
},
Creator(fcid) =>
@@ -128,7 +128,7 @@ impl Specifier {
fatcat_openapi::GetCreatorResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetCreatorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetCreatorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
CreatorLookup(ext_id, key) => {
let result = api_client.rt.block_on(match ext_id {
@@ -138,7 +138,7 @@ impl Specifier {
fatcat_openapi::LookupCreatorResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::LookupCreatorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::LookupCreatorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
}
},
File(fcid) =>
@@ -146,7 +146,7 @@ impl Specifier {
fatcat_openapi::GetFileResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetFileResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetFileResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
FileLookup(hash, key) => {
use FileLookupKey::*;
@@ -162,7 +162,7 @@ impl Specifier {
fatcat_openapi::LookupFileResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::LookupFileResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::LookupFileResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
}
},
FileSet(fcid) =>
@@ -170,35 +170,35 @@ impl Specifier {
fatcat_openapi::GetFilesetResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetFilesetResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetFilesetResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
WebCapture(fcid) =>
match api_client.rt.block_on(api_client.api.get_webcapture(fcid.to_string(), expand, hide))? {
fatcat_openapi::GetWebcaptureResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::GetWebcaptureResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetWebcaptureResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
Editgroup(fcid) =>
match api_client.rt.block_on(api_client.api.get_editgroup(fcid.to_string()))? {
fatcat_openapi::GetEditgroupResponse::Found(model) => Ok(Box::new(model)),
fatcat_openapi::GetEditgroupResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetEditgroupResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
Editor(fcid) =>
match api_client.rt.block_on(api_client.api.get_editor(fcid.to_string()))? {
fatcat_openapi::GetEditorResponse::Found(model) => Ok(Box::new(model)),
fatcat_openapi::GetEditorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetEditorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
Changelog(index) =>
match api_client.rt.block_on(api_client.api.get_changelog_entry(*index))? {
fatcat_openapi::GetChangelogEntryResponse::FoundChangelogEntry(model) => Ok(Box::new(model)),
fatcat_openapi::GetChangelogEntryResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
fatcat_openapi::GetChangelogEntryResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)),
- resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)),
+ resp => Err(anyhow!("{:?}", resp)).with_context(|| format!("API GET failed: {:?}", self)),
},
EditorUsername(_username) => {
unimplemented!("editor lookup by username isn't implemented in fatcat-server API yet, sorry")