aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 08:20:53 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 08:20:53 +0900
commit5aaa92f760a975c6617b5d1fb7af8e58fed127b7 (patch)
treee4d63e2f1456b2eab15c9c23ac48b895e100d5ad /crates/shirabe/src/command
parentb94e722ab71e06ab1f8a0be0ac4b76ba280fc73b (diff)
downloadphp-shirabe-5aaa92f760a975c6617b5d1fb7af8e58fed127b7.tar.gz
php-shirabe-5aaa92f760a975c6617b5d1fb7af8e58fed127b7.tar.zst
php-shirabe-5aaa92f760a975c6617b5d1fb7af8e58fed127b7.zip
refactor(check-platform-reqs-command): model the JSON output as structs
Replace the hand-built `IndexMap<String, PhpMixed>` rows behind `check-platform-reqs --format=json` with structs deriving `serde::Serialize`, so key order and the `null` values PHP keeps for a missing failed requirement or provider live in the type rather than being rebuilt at every insertion site. Test the provider against its raw value the way PHP's `$provider === ''` does, instead of against the `strip_tags` result. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command')
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs84
1 files changed, 34 insertions, 50 deletions
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index 3742cdac..d1cbf33c 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -27,6 +27,24 @@ struct CheckResult {
provider: String,
}
+/// Shape of one entry of the `check-platform-reqs --format=json` output.
+#[derive(Debug, serde::Serialize)]
+struct PlatformRequirementJson {
+ name: String,
+ version: String,
+ status: String,
+ failed_requirement: Option<FailedRequirementJson>,
+ provider: Option<String>,
+}
+
+#[derive(Debug, serde::Serialize)]
+struct FailedRequirementJson {
+ source: String,
+ r#type: String,
+ target: String,
+ constraint: String,
+}
+
#[derive(Debug)]
pub struct CheckPlatformReqsCommand {
base_command_data: BaseCommandData,
@@ -63,61 +81,27 @@ impl CheckPlatformReqsCommand {
let io = self.get_io();
if format == "json" {
- let rows: Vec<PhpMixed> = results
+ let rows: Vec<PlatformRequirementJson> = results
.iter()
- .map(|result| {
- let mut row = IndexMap::new();
- row.insert(
- "name".to_string(),
- PhpMixed::String(result.platform_package.clone()),
- );
- row.insert(
- "version".to_string(),
- PhpMixed::String(result.version.clone()),
- );
- row.insert(
- "status".to_string(),
- PhpMixed::String(strip_tags(&result.status)),
- );
- if let Some(link) = &result.link {
- let mut failed_req = IndexMap::new();
- failed_req.insert(
- "source".to_string(),
- PhpMixed::String(link.get_source().to_string()),
- );
- failed_req.insert(
- "type".to_string(),
- PhpMixed::String(link.get_description().to_string()),
- );
- failed_req.insert(
- "target".to_string(),
- PhpMixed::String(link.get_target().to_string()),
- );
- failed_req.insert(
- "constraint".to_string(),
- PhpMixed::String(link.get_pretty_constraint().to_string()),
- );
- row.insert(
- "failed_requirement".to_string(),
- PhpMixed::Array(failed_req),
- );
+ .map(|result| PlatformRequirementJson {
+ name: result.platform_package.clone(),
+ version: result.version.clone(),
+ status: strip_tags(&result.status),
+ failed_requirement: result.link.as_ref().map(|link| FailedRequirementJson {
+ source: link.get_source().to_string(),
+ r#type: link.get_description().to_string(),
+ target: link.get_target().to_string(),
+ constraint: link.get_pretty_constraint().to_string(),
+ }),
+ provider: if result.provider.is_empty() {
+ None
} else {
- row.insert("failed_requirement".to_string(), PhpMixed::Null);
- }
- let provider_str = strip_tags(&result.provider);
- row.insert(
- "provider".to_string(),
- if provider_str.is_empty() {
- PhpMixed::Null
- } else {
- PhpMixed::String(provider_str)
- },
- );
- PhpMixed::Array(row)
+ Some(strip_tags(&result.provider))
+ },
})
.collect();
- io.write(&JsonFile::encode(&PhpMixed::List(rows))?);
+ io.write(&JsonFile::encode(&rows)?);
} else {
let rows: Vec<PhpMixed> = results
.iter()