From c644aa4df0dfcd58e3f0a1372611921678ed6c6d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 23 Jun 2026 02:26:56 +0900 Subject: refactor(console): close HelperSet to a fixed set of four helpers Replace the dynamic, string-keyed HelperSet (set/has/get/get_iterator, HelperSetKey, deprecated set_command/get_command) with a closed set of FormatterHelper, DebugFormatterHelper, ProcessHelper and QuestionHelper instantiated by an argument-less constructor and exposed through typed getters (get_formatter/get_debug_formatter/get_process/get_question). The typed getters let ProcessHelper, QuestionHelper::write_error and InitCommand::interact drop their downcast/placeholder todo!() stubs. Dynamic registration of plugin-provided helpers is intentionally dropped for now and tracked via TODO(plugin) comments. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/console/application.rs | 49 ++++++------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) (limited to 'crates/shirabe/src/console/application.rs') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index c3287e7..8112e18 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -22,23 +22,18 @@ use shirabe_external_packages::symfony::console::exception::missing_input_except use shirabe_external_packages::symfony::console::exception::namespace_not_found_exception::NamespaceNotFoundException; use shirabe_external_packages::symfony::console::exception::runtime_exception::RuntimeException as ConsoleRuntimeException; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; -use shirabe_external_packages::symfony::console::helper::HelperInterface; use shirabe_external_packages::symfony::console::helper::HelperSet; -use shirabe_external_packages::symfony::console::helper::HelperSetKey; use shirabe_external_packages::symfony::console::helper::QuestionHelper; -use shirabe_external_packages::symfony::console::helper::debug_formatter_helper::DebugFormatterHelper; use shirabe_external_packages::symfony::console::helper::formatter_helper::{ FormatBlockMessages, FormatterHelper, }; use shirabe_external_packages::symfony::console::helper::helper::Helper; -use shirabe_external_packages::symfony::console::helper::process_helper::ProcessHelper; use shirabe_external_packages::symfony::console::input::InputDefinition; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::input::InputOption; use shirabe_external_packages::symfony::console::input::argv_input::ArgvInput; use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_argument::InputArgument; -use shirabe_external_packages::symfony::console::input::input_aware_interface::InputAwareInterface; use shirabe_external_packages::symfony::console::output::ConsoleOutputInterface; use shirabe_external_packages::symfony::console::output::console_output::ConsoleOutput; use shirabe_external_packages::symfony::console::output::output_interface::{ @@ -1633,33 +1628,10 @@ impl Application { } /// Gets the default helper set with the helpers that should always be available. + /// + /// The closed set of four helpers is instantiated by `HelperSet::new()` itself. pub fn get_default_helper_set(&self) -> std::rc::Rc> { - let helper_set = std::rc::Rc::new(std::cell::RefCell::new(HelperSet::default())); - let helpers: IndexMap>> = { - let mut m: IndexMap< - HelperSetKey, - std::rc::Rc>, - > = IndexMap::new(); - m.insert( - HelperSetKey::Int(0), - std::rc::Rc::new(std::cell::RefCell::new(FormatterHelper::default())), - ); - m.insert( - HelperSetKey::Int(1), - std::rc::Rc::new(std::cell::RefCell::new(DebugFormatterHelper::default())), - ); - m.insert( - HelperSetKey::Int(2), - std::rc::Rc::new(std::cell::RefCell::new(ProcessHelper::default())), - ); - m.insert( - HelperSetKey::Int(3), - std::rc::Rc::new(std::cell::RefCell::new(QuestionHelper::default())), - ); - m - }; - HelperSet::new(&helper_set, helpers); - helper_set + HelperSet::new() } /// Returns abbreviated suggestions in string format. @@ -2887,15 +2859,12 @@ impl ApplicationHandle { output: std::rc::Rc>, ) -> anyhow::Result { let application = &self.0; - if let Some(helper_set) = command.borrow().get_helper_set() { - for (_alias, helper) in helper_set.borrow().get_iterator() { - // if ($helper instanceof InputAwareInterface) $helper->setInput($input); - // TODO(review): downcasting a HelperInterface to InputAwareInterface is not - // expressible without a typed mechanism; needs design. - let _ = helper; - let _ = std::marker::PhantomData::; - } - } + // PHP: foreach ($command->getHelperSet() as $helper) { if ($helper instanceof + // InputAwareInterface) $helper->setInput($input); } + // TODO(plugin): the HelperSet is now a closed set of four helpers, none of which implement + // InputAwareInterface, so this loop is a no-op. Plugin-registered InputAware helpers cannot + // be reached until dynamic helper registration is restored (see HelperSet). + let _ = command.borrow().get_helper_set(); if !application.borrow().signals_to_dispatch_event.is_empty() { // $commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [] -- cgit v1.3.1