diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-19 17:43:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-19 17:53:42 +0900 |
| commit | d0cd98cd212bc13cbcfd0fd97fc245329b57f50f (patch) | |
| tree | 21bc56941b9f26247026893a9667450e275d5096 /crates/shirabe/src/command | |
| parent | 7e84d9ea31584e0dc04f04d14f6905ab9d978c72 (diff) | |
| download | php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.tar.gz php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.tar.zst php-shirabe-d0cd98cd212bc13cbcfd0fd97fc245329b57f50f.zip | |
fix(search-command): un-ignore test_search by fixing JSON output and abandoned propagation
The json format branch ignored search results entirely and always wrote
null. Encode results into the same name/description/abandoned/url shape
Composer's array-backed repositories produce. Also fix
ComposerRepository's RepositoryInterface::search adapter, which dropped
the abandoned field from raw API results even when present.
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/search_command.rs | 34 |
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) |
