From 145b4c0a7fadf6dfd8c03b22c735695037930b0a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 11:08:57 +0900 Subject: feat(console-input): port the suggested-values backport onto InputArgument/InputOption Composer backports symfony/console 6.1's $suggestedValues parameter in Composer\Console\Input\{InputArgument,InputOption}; the Rust newtypes had dropped it. PHP closures are bound to the command ($this), but a command cannot capture a handle to itself while configure() runs inside new(), so the closure receives the bound command as an explicit `this` argument at call time instead. - add SuggestedValues (list | this-taking closure) and wire it through InputArgument::new5 / InputOption::new6 and their complete() methods - track Composer-typed definition entries by name in BaseCommandData side maps, standing in for PHP's instanceof checks (set_definition converts entries to the Symfony types for storage) - add base_command_complete, the BaseCommand::complete dispatch shared by every Composer command - introduce BaseCommand::base_command_data and make command_data a default method on top of it Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/console/input/input_argument.rs | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'crates/shirabe/src/console/input/input_argument.rs') diff --git a/crates/shirabe/src/console/input/input_argument.rs b/crates/shirabe/src/console/input/input_argument.rs index 5fd9cecc..ab32ffba 100644 --- a/crates/shirabe/src/console/input/input_argument.rs +++ b/crates/shirabe/src/console/input/input_argument.rs @@ -1,11 +1,15 @@ //! ref: composer/src/Composer/Console/Input/InputArgument.php +use crate::console::input::SuggestedValues; +use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; +use shirabe_external_packages::symfony::console::completion::completion_suggestions::CompletionSuggestions; use shirabe_external_packages::symfony::console::input::InputArgument as BaseInputArgument; use shirabe_php_shim::PhpMixed; #[derive(Debug)] pub struct InputArgument { inner: BaseInputArgument, + suggested_values: SuggestedValues, } impl InputArgument { @@ -18,7 +22,23 @@ impl InputArgument { mode: Option, description: &str, default: Option, - // TODO(cli-completion): suggested_values closure / list dropped along with completion support + ) -> anyhow::Result { + Self::new5( + name, + mode, + description, + default, + SuggestedValues::List(Vec::new()), + ) + } + + /// PHP's constructor with the fifth parameter, `$suggestedValues`. + pub fn new5( + name: &str, + mode: Option, + description: &str, + default: Option, + suggested_values: SuggestedValues, ) -> anyhow::Result { let inner = BaseInputArgument::new( name.to_string(), @@ -26,7 +46,27 @@ impl InputArgument { description.to_string(), default.unwrap_or(PhpMixed::Null), )?; - Ok(Self { inner }) + Ok(Self { + inner, + suggested_values, + }) + } + + /// Adds suggestions to `suggestions` for the current completion input. + /// + /// PHP closures are bound to the command; `this` is the command dispatching the + /// completion (see [`SuggestedValues`]). + pub fn complete( + &self, + this: &dyn crate::command::BaseCommand, + input: &CompletionInput, + suggestions: &mut CompletionSuggestions, + ) -> anyhow::Result<()> { + self.suggested_values.complete(this, input, suggestions) + } + + pub(crate) fn get_name(&self) -> String { + self.inner.get_name().to_string() } /// Unwraps to the underlying Symfony `InputArgument` (used when forwarding a Composer-typed -- cgit v1.3.1