aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/fatcat-cli/src/main.rs26
-rw-r--r--rust/fatcat-cli/src/specifier.rs32
2 files changed, 35 insertions, 23 deletions
diff --git a/rust/fatcat-cli/src/main.rs b/rust/fatcat-cli/src/main.rs
index ccd47d3..0e5e4e8 100644
--- a/rust/fatcat-cli/src/main.rs
+++ b/rust/fatcat-cli/src/main.rs
@@ -81,6 +81,12 @@ enum Command {
Get {
specifier: Specifier,
+ #[structopt(long = "--expand")]
+ expand: Option<String>,
+
+ #[structopt(long = "--hide")]
+ hide: Option<String>,
+
#[structopt(long)]
toml: bool,
},
@@ -137,6 +143,12 @@ enum Command {
terms: Vec<String>,
+ #[structopt(long = "--expand")]
+ expand: Option<String>,
+
+ #[structopt(long = "--hide")]
+ hide: Option<String>,
+
#[structopt(long, short, default_value = "20")]
limit: i64,
@@ -203,8 +215,8 @@ fn run(opt: Opt) -> Result<()> {
let mut api_client = FatcatApiClient::new(&client, opt.api_host.clone(), opt.api_token.clone())?;
match opt.cmd {
- Command::Get {toml, specifier} => {
- let result = specifier.get_from_api(&mut api_client)?;
+ Command::Get {toml, specifier, expand, hide } => {
+ let result = specifier.get_from_api(&mut api_client, expand, hide)?;
if toml {
writeln!(&mut std::io::stdout(), "{}", result.to_toml_string()?)?
} else {
@@ -224,7 +236,7 @@ fn run(opt: Opt) -> Result<()> {
},
// no input path *and* mutations: fetch from API
(None, _) => {
- let mut entity = specifier.get_from_api(&mut api_client)?;
+ let mut entity = specifier.get_from_api(&mut api_client, None, None)?;
entity.mutate(mutations)?;
(entity.to_json_string()?, entity.specifier())
},
@@ -236,7 +248,7 @@ fn run(opt: Opt) -> Result<()> {
// TODO: fetch editgroup, check if this entity is already being updated in it. If so,
// need to fetch that revision, do the edit, parse that synatx is good, then delete the
// existing edit and update with the new one.
- let original_entity = specifier.get_from_api(&mut api_client)?;
+ let original_entity = specifier.get_from_api(&mut api_client, None, None)?;
let exact_specifier = original_entity.specifier();
let tmp_file = tempfile::Builder::new()
.suffix( if json { ".json" } else { ".toml"} )
@@ -257,11 +269,11 @@ fn run(opt: Opt) -> Result<()> {
let json_str = read_entity_file(Some(tmp_file.path().to_path_buf()))?;
// for whatever reason api_client's TCP connection is broken after spawning, so try a
// dummy call, expected to fail, but connection should re-establish after this
- specifier.get_from_api(&mut api_client).context("re-fetch").ok();
+ specifier.get_from_api(&mut api_client, None, None).context("re-fetch").ok();
let ee = api_client.update_entity_from_json(exact_specifier, &json_str, editgroup_id).context("updating after edit")?;
println!("{}", serde_json::to_string(&ee)?);
},
- Command::Search { entity_type, terms, limit, search_schema } => {
+ Command::Search { entity_type, terms, limit, search_schema, expand, hide } => {
let limit: Option<u64> = match limit {
l if l < 0 => None,
l => Some(l as u64),
@@ -275,7 +287,7 @@ fn run(opt: Opt) -> Result<()> {
(true, _) => writeln!(&mut std::io::stdout(), "{}", hit.to_string())?,
(false, EntityType::Release) => {
let specifier = Specifier::Release(hit["ident"].as_str().unwrap().to_string());
- let entity = specifier.get_from_api(&mut api_client)?;
+ let entity = specifier.get_from_api(&mut api_client, expand.clone(), hide.clone())?;
writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)?
},
(false, _) => unimplemented!("searching other entity types"),
diff --git a/rust/fatcat-cli/src/specifier.rs b/rust/fatcat-cli/src/specifier.rs
index 0cb5014..c2834b0 100644
--- a/rust/fatcat-cli/src/specifier.rs
+++ b/rust/fatcat-cli/src/specifier.rs
@@ -60,21 +60,21 @@ impl Specifier {
use Specifier::*;
match self {
Release(_) | Work(_) | Creator(_) | Container(_) | File(_) | FileSet(_) | WebCapture(_) | Editgroup(_) | Editor(_) | Changelog(_) => Ok(self),
- ReleaseLookup(_, _) => Ok(self.get_from_api(api_client)?.specifier()),
- ContainerLookup(_, _) => Ok(self.get_from_api(api_client)?.specifier()),
- CreatorLookup(_, _) => Ok(self.get_from_api(api_client)?.specifier()),
- FileLookup(_, _) => Ok(self.get_from_api(api_client)?.specifier()),
+ ReleaseLookup(_, _) => Ok(self.get_from_api(api_client, None, None)?.specifier()),
+ ContainerLookup(_, _) => Ok(self.get_from_api(api_client, None, None)?.specifier()),
+ CreatorLookup(_, _) => Ok(self.get_from_api(api_client, None, None)?.specifier()),
+ FileLookup(_, _) => Ok(self.get_from_api(api_client, None, None)?.specifier()),
EditorUsername(_username) => {
Err(anyhow!("editor lookup by username isn't implemented in fatcat-server API yet, sorry"))
},
}
}
- pub fn get_from_api(&self, api_client: &mut FatcatApiClient) -> Result<Box<dyn ApiEntityModel>> {
+ pub fn get_from_api(&self, api_client: &mut FatcatApiClient, expand: Option<String>, hide: Option<String>) -> Result<Box<dyn ApiEntityModel>> {
use Specifier::*;
let ret: Result<Box<dyn ApiEntityModel>> = match self {
Release(fcid) =>
- match api_client.rt.block_on(api_client.api.get_release(fcid.to_string(), None, None))? {
+ match api_client.rt.block_on(api_client.api.get_release(fcid.to_string(), expand, hide))? {
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)),
@@ -90,7 +90,7 @@ impl Specifier {
);
// doi, wikidata, isbn13, pmid, pmcid, core, arxiv, jstor, ark, mag
let result = api_client.rt.block_on(
- api_client.api.lookup_release(doi, None, None, pmid, pmcid, None, arxiv, None, None, None, None, None))?;
+ api_client.api.lookup_release(doi, None, None, pmid, pmcid, None, arxiv, None, None, None, expand, hide))?;
match result {
fatcat_openapi::LookupReleaseResponse::FoundEntity(model) => Ok(Box::new(model)),
fatcat_openapi::LookupReleaseResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)),
@@ -99,14 +99,14 @@ impl Specifier {
}
},
Work(fcid) =>
- match api_client.rt.block_on(api_client.api.get_work(fcid.to_string(), None, None))? {
+ match api_client.rt.block_on(api_client.api.get_work(fcid.to_string(), expand, hide))? {
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)),
},
Container(fcid) =>
- match api_client.rt.block_on(api_client.api.get_container(fcid.to_string(), None, None))? {
+ 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)),
@@ -114,7 +114,7 @@ impl Specifier {
},
ContainerLookup(ext_id, key) => {
let result = api_client.rt.block_on(match ext_id {
- ContainerLookupKey::ISSNL => api_client.api.lookup_container(Some(key.to_string()), None, None, None),
+ ContainerLookupKey::ISSNL => api_client.api.lookup_container(Some(key.to_string()), None, expand, hide),
})?;
match result {
fatcat_openapi::LookupContainerResponse::FoundEntity(model) => Ok(Box::new(model)),
@@ -124,7 +124,7 @@ impl Specifier {
}
},
Creator(fcid) =>
- match api_client.rt.block_on(api_client.api.get_creator(fcid.to_string(), None, None))? {
+ match api_client.rt.block_on(api_client.api.get_creator(fcid.to_string(), expand, hide))? {
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)),
@@ -132,7 +132,7 @@ impl Specifier {
},
CreatorLookup(ext_id, key) => {
let result = api_client.rt.block_on(match ext_id {
- CreatorLookupKey::Orcid => api_client.api.lookup_creator(Some(key.to_string()), None, None, None),
+ CreatorLookupKey::Orcid => api_client.api.lookup_creator(Some(key.to_string()), None, expand, hide),
})?;
match result {
fatcat_openapi::LookupCreatorResponse::FoundEntity(model) => Ok(Box::new(model)),
@@ -142,7 +142,7 @@ impl Specifier {
}
},
File(fcid) =>
- match api_client.rt.block_on(api_client.api.get_file(fcid.to_string(), None, None))? {
+ match api_client.rt.block_on(api_client.api.get_file(fcid.to_string(), expand, hide))? {
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)),
@@ -156,7 +156,7 @@ impl Specifier {
if let MD5 = hash { Some(key.to_string()) } else { None },
);
let result = api_client.rt.block_on(
- api_client.api.lookup_file(sha1, sha256, md5, None, None),
+ api_client.api.lookup_file(sha1, sha256, md5, expand, hide),
)?;
match result {
fatcat_openapi::LookupFileResponse::FoundEntity(model) => Ok(Box::new(model)),
@@ -166,14 +166,14 @@ impl Specifier {
}
},
FileSet(fcid) =>
- match api_client.rt.block_on(api_client.api.get_fileset(fcid.to_string(), None, None))? {
+ match api_client.rt.block_on(api_client.api.get_fileset(fcid.to_string(), expand, hide))? {
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)),
},
WebCapture(fcid) =>
- match api_client.rt.block_on(api_client.api.get_webcapture(fcid.to_string(), None, None))? {
+ 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)),