From 91ccd49cf68bca199e7d41fa65a4a3b0d1368127 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 29 Jun 2026 21:56:39 +0900 Subject: feat(php-shim): implement DirectoryIterator in fs shim Give DirectoryIteratorEntry a backing path (mirroring RecursiveIteratorFileInfo) and make directory_iterator enumerate entries, returning Result to match PHP DirectoryIterator's UnexpectedValueException on an unopenable directory. Wire the new Result through DumpCompletionCommand's get_supported_shells. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../console/command/dump_completion_command.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/shirabe-external-packages/src') diff --git a/crates/shirabe-external-packages/src/symfony/console/command/dump_completion_command.rs b/crates/shirabe-external-packages/src/symfony/console/command/dump_completion_command.rs index 588b868..8e2583e 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/dump_completion_command.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command/dump_completion_command.rs @@ -63,12 +63,12 @@ impl DumpCompletionCommand { pub fn complete_impl(&self, input: &CompletionInput, suggestions: &mut CompletionSuggestions) { if input.must_suggest_argument_values_for("shell") { - suggestions.suggest_values( - self.get_supported_shells() - .into_iter() - .map(StringOrSuggestion::String) - .collect(), - ); + // TODO(phase-d): PHP's complete() lets a DirectoryIterator failure propagate, but the + // Command::complete trait is infallible; on error the suggestions are skipped instead. + if let Ok(shells) = self.get_supported_shells() { + suggestions + .suggest_values(shells.into_iter().map(StringOrSuggestion::String).collect()); + } } } @@ -98,14 +98,14 @@ impl DumpCompletionCommand { todo!() } - fn get_supported_shells(&self) -> Vec { + fn get_supported_shells(&self) -> anyhow::Result> { let mut shells = vec![]; // foreach (new \DirectoryIterator(__DIR__.'/../Resources/') as $file) for file in shirabe_php_shim::directory_iterator(&format!( "{}/../Resources/", shirabe_php_shim::dir() - )) { + ))? { if shirabe_php_shim::str_starts_with(&file.get_basename(), "completion.") && file.is_file() { @@ -113,7 +113,7 @@ impl DumpCompletionCommand { } } - shells + Ok(shells) } } @@ -209,7 +209,7 @@ impl Command for DumpCompletionCommand { shell ); if !shirabe_php_shim::file_exists(&completion_file) { - let supported_shells = self.get_supported_shells(); + let supported_shells = self.get_supported_shells()?; // TODO: PHP does `$output instanceof ConsoleOutputInterface ? $output->getErrorOutput() // : $output`. There is no way to test trait membership through `&dyn OutputInterface` -- cgit v1.3.1