summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat-cli/src/commands.rs8
-rw-r--r--fatcat-cli/src/lib.rs4
-rw-r--r--fatcat-cli/src/main.rs28
-rw-r--r--fatcat-cli/src/search.rs6
4 files changed, 42 insertions, 4 deletions
diff --git a/fatcat-cli/src/commands.rs b/fatcat-cli/src/commands.rs
index 5b456d7..87a0f5a 100644
--- a/fatcat-cli/src/commands.rs
+++ b/fatcat-cli/src/commands.rs
@@ -295,7 +295,9 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType)
SearchEntityType::Scholar => {
writeln!(tw, "key\ttype\tstage\tyear\tcontainer_name\ttitle")?;
}
- SearchEntityType::Reference => {
+ SearchEntityType::Reference
+ | SearchEntityType::ReferenceIn
+ | SearchEntityType::ReferenceOut => {
writeln!(tw, "source\tkey\tprovenance\tstatus\ttarget")?;
}
}
@@ -351,7 +353,9 @@ pub fn print_search_table(results: SearchResults, entity_type: SearchEntityType)
hit["biblio"]["title"].as_str().unwrap_or("-"),
)?;
}
- SearchEntityType::Reference => {
+ SearchEntityType::Reference
+ | SearchEntityType::ReferenceIn
+ | SearchEntityType::ReferenceOut => {
writeln!(
tw,
"{}\t{}\t{}\t{}\t{}",
diff --git a/fatcat-cli/src/lib.rs b/fatcat-cli/src/lib.rs
index e8b112f..ab63ec7 100644
--- a/fatcat-cli/src/lib.rs
+++ b/fatcat-cli/src/lib.rs
@@ -59,6 +59,8 @@ pub enum SearchEntityType {
File,
Scholar,
Reference,
+ ReferenceIn,
+ ReferenceOut,
}
impl FromStr for SearchEntityType {
@@ -71,6 +73,8 @@ impl FromStr for SearchEntityType {
"file" | "files" => Ok(SearchEntityType::File),
"scholar" | "fulltext" => Ok(SearchEntityType::Scholar),
"ref" | "refs" | "references" => Ok(SearchEntityType::Reference),
+ "ref-in" | "refs-in" | "references-in" => Ok(SearchEntityType::ReferenceIn),
+ "ref-out" | "refs-out" | "references-out" => Ok(SearchEntityType::ReferenceOut),
_ => Err(anyhow!("invalid entity type : {}", s)),
}
}
diff --git a/fatcat-cli/src/main.rs b/fatcat-cli/src/main.rs
index 9e995d2..af22f85 100644
--- a/fatcat-cli/src/main.rs
+++ b/fatcat-cli/src/main.rs
@@ -670,6 +670,34 @@ fn run(opt: Opt) -> Result<()> {
"entity schema output not supported for references index"
));
}
+ (false, true, SearchEntityType::ReferenceIn) => {
+ if !hit["source_release_ident"].is_string() {
+ continue;
+ }
+ let specifier = Specifier::Release(
+ hit["source_release_ident"].as_str().unwrap().to_string(),
+ );
+ let entity = specifier.get_from_api(
+ &mut api_client,
+ expand.clone(),
+ hide.clone(),
+ )?;
+ writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)?
+ }
+ (false, true, SearchEntityType::ReferenceOut) => {
+ if !hit["target_release_ident"].is_string() {
+ continue;
+ }
+ let specifier = Specifier::Release(
+ hit["target_release_ident"].as_str().unwrap().to_string(),
+ );
+ let entity = specifier.get_from_api(
+ &mut api_client,
+ expand.clone(),
+ hide.clone(),
+ )?;
+ writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)?
+ }
}
}
}
diff --git a/fatcat-cli/src/search.rs b/fatcat-cli/src/search.rs
index 0dea37f..f467c83 100644
--- a/fatcat-cli/src/search.rs
+++ b/fatcat-cli/src/search.rs
@@ -80,7 +80,9 @@ pub fn crude_search(
SearchEntityType::Container => "fatcat_container",
SearchEntityType::File => "fatcat_file",
SearchEntityType::Scholar => "scholar_fulltext",
- SearchEntityType::Reference => "fatcat_ref",
+ SearchEntityType::Reference
+ | SearchEntityType::ReferenceIn
+ | SearchEntityType::ReferenceOut => "fatcat_ref",
};
let http_client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(10))
@@ -219,7 +221,7 @@ pub fn crude_search(
"sort": [ sort_mode ],
"track_total_hits": true,
}),
- SearchEntityType::Reference => json!({
+ SearchEntityType::Reference | SearchEntityType::ReferenceIn | SearchEntityType::ReferenceOut => json!({
"query": {
"query_string": {
"query": query,