aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 08:42:56 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 08:42:56 +0900
commit92f5c977b42d1322f3cebb260024179e1285b9d0 (patch)
tree6152b6491d01c4478de4d5b5a8dbb0ea5e5e33c8 /crates/shirabe-external-packages
parentb5d6d91054b9ceef95aef0819bb5c4ef7db1abdd (diff)
downloadphp-shirabe-92f5c977b42d1322f3cebb260024179e1285b9d0.tar.gz
php-shirabe-92f5c977b42d1322f3cebb260024179e1285b9d0.tar.zst
php-shirabe-92f5c977b42d1322f3cebb260024179e1285b9d0.zip
fix(symfony-console): dispatch parse_token to CompletionInput in bind
PHP's Input::bind() -> ArgvInput::parse() calls $this->parseToken(), which late-binds to CompletionInput::parseToken; that override swallows per-token RuntimeExceptions so an incomplete command line still parses. Delegating CompletionInput::bind to ArgvInput::bind pinned the call to ArgvInput's parseToken, aborting the whole parse on the first invalid token and leaving CompletionInput::parse_token dead. parseToken is protected and not on any trait, so ArgvInput::base_bind threads the concrete implementation in as a callback instead of a trait object. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs22
2 files changed, 28 insertions, 6 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs
index d076f8a3..a16575de 100644
--- a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs
@@ -57,7 +57,10 @@ impl CompletionInput {
}
pub fn bind(&mut self, definition: &InputDefinition) -> anyhow::Result<()> {
- self.inner.bind(definition)?;
+ self.inner
+ .base_bind(definition, |argv, token, parse_options| {
+ Ok(CompletionInput::parse_token(argv, token, parse_options))
+ })?;
let relevant_token = self.get_relevant_token();
if "-" == &relevant_token[0..1] {
@@ -203,8 +206,11 @@ impl CompletionInput {
self.inner.get_first_argument()
}
- pub(crate) fn parse_token(&mut self, token: &str, parse_options: bool) -> bool {
- match self.inner.parse_token(token, parse_options) {
+ /// PHP `CompletionInput::parseToken` (called back from `ArgvInput::base_bind`). Takes the
+ /// embedded ArgvInput instead of `&mut self` because the parse loop already holds the
+ /// exclusive borrow of it.
+ fn parse_token(inner: &mut ArgvInput, token: &str, parse_options: bool) -> bool {
+ match inner.parse_token(token, parse_options) {
Ok(value) => return value,
Err(_e) => {
// suppress errors, completed input is almost never valid
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
index bf1ea659..59828631 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
@@ -76,21 +76,37 @@ impl ArgvInput {
}
pub fn bind(&mut self, definition: &InputDefinition) -> anyhow::Result<()> {
+ self.base_bind(definition, ArgvInput::parse_token)
+ }
+
+ /// Shared body of `bind` (PHP `Input::bind`). PHP's `$this->parse()` ends in
+ /// `$this->parseToken()`, which late-binds to `CompletionInput::parseToken`; `parseToken`
+ /// is protected and not part of any trait, so the concrete implementation is threaded in
+ /// as a callback taking the embedded ArgvInput.
+ pub(crate) fn base_bind(
+ &mut self,
+ definition: &InputDefinition,
+ parse_token: impl FnMut(&mut ArgvInput, &str, bool) -> anyhow::Result<bool>,
+ ) -> anyhow::Result<()> {
self.inner.arguments = IndexMap::new();
self.inner.options = IndexMap::new();
self.inner.definition = definition.clone();
- self.parse()?;
+ self.base_parse(parse_token)?;
Ok(())
}
- fn parse(&mut self) -> anyhow::Result<()> {
+ /// Shared body of `parse`; see `base_bind` for why `parse_token` is a parameter.
+ fn base_parse(
+ &mut self,
+ mut parse_token: impl FnMut(&mut ArgvInput, &str, bool) -> anyhow::Result<bool>,
+ ) -> anyhow::Result<()> {
let mut parse_options = true;
self.parsed = self.tokens.clone();
while !self.parsed.is_empty() {
let token = self.parsed.remove(0);
- parse_options = self.parse_token(&token, parse_options)?;
+ parse_options = parse_token(self, &token, parse_options)?;
}
Ok(())
}