From 4856f05e870ec5d2daaa74bf9a86a1519a813614 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 08:37:30 +0900 Subject: fix(input): return a bool|string|string[]|null enum from get_option `InputInterface::get_option` returned `PhpMixed`, so the negation branch of `Input::get_option` reproduced PHP's `return !$value;` as `!value.as_bool().unwrap_or(false)`, which inverts the result for a string value instead of leaving it `false`. It now returns `InputOptionValue`, whose `to_bool` is PHP's truthiness cast. The narrowing also removes the `Vec` element handling the commands carried for array options: `as_array` hands back `&[String]`, so the `filter_map(|v| v.as_string())` chains at eight call sites collapse. Its other accessors keep `PhpMixed`'s names and meanings (`is_null`, `as_bool`, `as_string`, `to_bool`), and `From for PhpMixed` covers the callers that feed the value back into an `IndexMap` or a `PhpMixed` parameter. `Input` keeps its parsed options and `InputOption` its defaults as `PhpMixed`, so `Input::get_option` is where the narrowing happens and where a value outside the domain panics. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/reinstall_command.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/command/reinstall_command.rs') diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index 010d2b5d..43978191 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -91,7 +91,7 @@ impl Command for ReinstallCommand { let mut package_names_to_reinstall: Vec = vec![]; let type_option = input.borrow().get_option("type")?; - let type_count = type_option.as_list().map_or(0, |l| l.len()); + let type_count = type_option.as_array().map_or(0, <[String]>::len); let packages_arg = input.borrow().get_argument("packages")?; let packages_count = packages_arg.as_list().map_or(0, |l| l.len()); @@ -104,12 +104,8 @@ impl Command for ReinstallCommand { .into()); } let filter_types: Vec = type_option - .as_list() - .map(|l| { - l.iter() - .filter_map(|v| v.as_string().map(|s| s.to_string())) - .collect() - }) + .as_array() + .map(<[String]>::to_vec) .unwrap_or_default(); for package in local_repo.get_canonical_packages()? { if filter_types.contains(&package.get_type()) { -- cgit v1.3.1-4-g156e