From 6051927c8fa32cfffa102d2a170c5a6cf747a1b9 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 11:19:03 +0900 Subject: refactor(symfony-console): extract symfony/console into the shirabe-symfony-console crate Move `Symfony\Component\Console` out of shirabe-external-packages and into its own crate, so the path is `shirabe_symfony_console::application::Application` instead of `shirabe_external_packages::symfony::console::application::Application`. The `delegate_to_inner!` and `delegate_command_trait_impls_to_inner!` macros move with it. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/tester/command_completion_tester.rs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 crates/shirabe-symfony-console/src/tester/command_completion_tester.rs (limited to 'crates/shirabe-symfony-console/src/tester/command_completion_tester.rs') diff --git a/crates/shirabe-symfony-console/src/tester/command_completion_tester.rs b/crates/shirabe-symfony-console/src/tester/command_completion_tester.rs new file mode 100644 index 00000000..81cbdab3 --- /dev/null +++ b/crates/shirabe-symfony-console/src/tester/command_completion_tester.rs @@ -0,0 +1,54 @@ +//! ref: composer/vendor/symfony/console/Tester/CommandCompletionTester.php + +use crate::command::command::Command; +use crate::completion::completion_input::CompletionInput; +use crate::completion::completion_suggestions::CompletionSuggestions; + +/// Eases the testing of command completion. +#[derive(Debug)] +pub struct CommandCompletionTester { + command: std::rc::Rc>, +} + +impl CommandCompletionTester { + pub fn new(command: std::rc::Rc>) -> Self { + Self { command } + } + + /// Create completion suggestions from input tokens. + pub fn complete(&self, input: &[&str]) -> anyhow::Result> { + let mut input: Vec = input.iter().map(|s| s.to_string()).collect(); + let current_index = input.len() as i64; + if input.last().map(String::as_str) == Some("") { + input.pop(); + } + // array_unshift($input, $this->command->getName()) + input.insert(0, self.command.borrow().get_name().unwrap_or_default()); + + let mut completion_input = CompletionInput::from_tokens(input, current_index)?; + { + let command_ref = self.command.borrow(); + let definition = command_ref.get_definition(); + completion_input.bind(&definition)?; + } + let mut suggestions = CompletionSuggestions::new(); + + self.command + .borrow() + .complete(&completion_input, &mut suggestions)?; + + let mut result: Vec = suggestions + .get_option_suggestions() + .iter() + .map(|option| format!("--{}", option.get_name())) + .collect(); + // array_map('strval', ... $suggestions->getValueSuggestions()) + result.extend( + suggestions + .get_value_suggestions() + .iter() + .map(|suggestion| suggestion.to_string()), + ); + Ok(result) + } +} -- cgit v1.3.1-4-g156e