aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe/src/command/search_command.rs34
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs7
-rw-r--r--crates/shirabe/tests/command/search_command_test.rs1
3 files changed, 36 insertions, 6 deletions
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 6709613c..1f77889e 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -11,7 +11,7 @@ use crate::plugin::PluginEvents;
use crate::repository::CompositeRepository;
use crate::repository::PlatformRepository;
use crate::repository::RepositoryInterfaceHandle;
-use crate::repository::repository_interface::{self, RepositoryInterface};
+use crate::repository::repository_interface::{self, AbandonedInfo, RepositoryInterface};
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
@@ -259,9 +259,35 @@ impl Command for SearchCommand {
// TODO(phase-c): faithful JSON output requires SearchResult to retain the raw result
// array. PHP's fulltext search passes through arbitrary API fields (downloads, favers,
// repository, ...) which the typed SearchResult (name/description/abandoned/url) drops,
- // so encoding it here would diverge from Composer's output.
- let _ = &results;
- io.write(&JsonFile::encode(&PhpMixed::Null));
+ // so ComposerRepository-sourced results still diverge from Composer's raw JSON output.
+ let rows: Vec<PhpMixed> = results
+ .into_iter()
+ .map(|result| {
+ let mut entry = IndexMap::new();
+ entry.insert("name".to_string(), PhpMixed::String(result.name));
+ entry.insert(
+ "description".to_string(),
+ result
+ .description
+ .map(PhpMixed::String)
+ .unwrap_or(PhpMixed::Null),
+ );
+ if let Some(abandoned) = result.abandoned {
+ entry.insert(
+ "abandoned".to_string(),
+ match abandoned {
+ AbandonedInfo::Replacement(s) => PhpMixed::String(s),
+ AbandonedInfo::Abandoned => PhpMixed::Bool(true),
+ },
+ );
+ }
+ if let Some(url) = result.url {
+ entry.insert("url".to_string(), PhpMixed::String(url));
+ }
+ PhpMixed::Array(entry)
+ })
+ .collect();
+ io.write(&JsonFile::encode(&PhpMixed::List(rows)));
}
Ok(0)
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 54edc39a..580667b5 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -3575,7 +3575,12 @@ impl RepositoryInterface for ComposerRepository {
.get("description")
.and_then(|v| v.as_string())
.map(|s| s.to_string()),
- abandoned: None,
+ abandoned: m.get("abandoned").filter(|v| v.to_bool()).map(|v| {
+ match v.as_string() {
+ Some(s) => crate::repository::AbandonedInfo::Replacement(s.to_string()),
+ None => crate::repository::AbandonedInfo::Abandoned,
+ }
+ }),
url: m
.get("url")
.and_then(|v| v.as_string())
diff --git a/crates/shirabe/tests/command/search_command_test.rs b/crates/shirabe/tests/command/search_command_test.rs
index 69f2930c..7806ea0f 100644
--- a/crates/shirabe/tests/command/search_command_test.rs
+++ b/crates/shirabe/tests/command/search_command_test.rs
@@ -36,7 +36,6 @@ fn run_search_case(command: Vec<(PhpMixed, PhpMixed)>, expected: &str) {
#[test]
#[serial]
-#[ignore = "searching a `package`-type repo returns incomplete results (some matching packages are dropped); the search/repository path is not yet fully ported"]
fn test_search() {
// 'by name and description'
run_search_case(