aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/command')
-rw-r--r--crates/shirabe/src/command/search_command.rs34
1 files changed, 30 insertions, 4 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)