diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 08:37:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 08:37:30 +0900 |
| commit | 4856f05e870ec5d2daaa74bf9a86a1519a813614 (patch) | |
| tree | ab81b7a9d59340c4d05ecaf3b6b1a81106cc8355 /crates/shirabe/src/command/show_command.rs | |
| parent | 5aaa92f760a975c6617b5d1fb7af8e58fed127b7 (diff) | |
| download | php-shirabe-4856f05e870ec5d2daaa74bf9a86a1519a813614.tar.gz php-shirabe-4856f05e870ec5d2daaa74bf9a86a1519a813614.tar.zst php-shirabe-4856f05e870ec5d2daaa74bf9a86a1519a813614.zip | |
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<PhpMixed>` 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<InputOptionValue> for PhpMixed` covers the callers that feed the
value back into an `IndexMap<String, PhpMixed>` 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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command/show_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/show_command.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index 34b84fd8..3cc80b4c 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -1489,8 +1489,8 @@ impl Command for ShowCommand { } else if input .borrow() .get_option("ignore")? - .as_list() - .map_or(0, |l| l.len()) + .as_array() + .map_or(0, <[String]>::len) > 0 { self.get_io().write_error("<warning>You are using the option \"ignore\" for action other than \"outdated\", it will be ignored.</warning>"); @@ -2180,12 +2180,8 @@ impl Command for ShowCommand { &input .borrow() .get_option("ignore")? - .as_list() - .map(|l| { - l.iter() - .filter_map(|v| v.as_string().map(strtolower)) - .collect::<Vec<_>>() - }) + .as_array() + .map(|l| l.iter().map(|v| strtolower(v)).collect::<Vec<_>>()) .unwrap_or_default(), "{^(?:%s)$}iD", ); |
