aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/helper
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/helper')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs29
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs22
2 files changed, 18 insertions, 33 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
index 9eb8fff..1fc90bd 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
@@ -15,8 +15,8 @@ use crate::symfony::console::output::console_output_interface::ConsoleOutputInte
use crate::symfony::console::output::console_section_output::ConsoleSectionOutput;
use crate::symfony::console::output::output_interface;
use crate::symfony::console::output::output_interface::OutputInterface;
-use crate::symfony::console::question::choice_question::ChoiceQuestion;
-use crate::symfony::console::question::question::Question;
+use crate::symfony::console::question::ChoiceQuestion;
+use crate::symfony::console::question::QuestionInterface;
use crate::symfony::console::terminal::Terminal;
use crate::symfony::string::s;
use shirabe_php_shim::AsAny;
@@ -48,7 +48,7 @@ impl QuestionHelper {
&mut self,
input: &mut dyn InputInterface,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
) -> anyhow::Result<Result<PhpMixed, MissingInputException>> {
let mut output = output;
let error_output = {
@@ -115,7 +115,7 @@ impl QuestionHelper {
fn do_ask(
&self,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
) -> anyhow::Result<Result<PhpMixed, MissingInputException>> {
self.write_prompt(Rc::clone(&output), question);
@@ -220,7 +220,7 @@ impl QuestionHelper {
}
/// @return mixed
- fn get_default_answer(&self, question: &Question) -> PhpMixed {
+ fn get_default_answer(&self, question: &impl QuestionInterface) -> PhpMixed {
let default = question.get_default();
if matches!(default, PhpMixed::Null) {
@@ -230,7 +230,7 @@ impl QuestionHelper {
if let Some(validator) = question.get_validator() {
// call_user_func($question->getValidator(), $default)
return validator(Some(default)).unwrap();
- } else if let Some(choice_question) = question_as_choice_question(question) {
+ } else if let Some(choice_question) = question.as_choice() {
let choices = choice_question.get_choices();
if !choice_question.is_multiselect() {
@@ -262,11 +262,11 @@ impl QuestionHelper {
pub(crate) fn write_prompt(
&self,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
) {
let mut message = question.get_question().to_string();
- if let Some(choice_question) = question_as_choice_question(question) {
+ if let Some(choice_question) = question.as_choice() {
let mut lines = vec![question.get_question().to_string()];
lines.extend(self.format_choice_question_choices(choice_question, "info"));
output
@@ -339,7 +339,7 @@ impl QuestionHelper {
fn autocomplete(
&self,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
input_stream: &shirabe_php_shim::PhpResource,
autocomplete: &dyn Fn(&str) -> Vec<PhpMixed>,
) -> String {
@@ -518,7 +518,7 @@ impl QuestionHelper {
let mut temp_ret = ret.clone();
- if let Some(choice_question) = question_as_choice_question(question)
+ if let Some(choice_question) = question.as_choice()
&& choice_question.is_multiselect()
{
temp_ret = self.most_recently_entered_value(&full_choice);
@@ -680,7 +680,7 @@ impl QuestionHelper {
&self,
interviewer: &dyn Fn() -> anyhow::Result<Result<PhpMixed, MissingInputException>>,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
) -> anyhow::Result<Result<PhpMixed, MissingInputException>> {
let mut error: Option<shirabe_php_shim::Exception> = None;
let mut attempts = question.get_max_attempts();
@@ -752,7 +752,7 @@ impl QuestionHelper {
fn read_input(
&self,
input_stream: &shirabe_php_shim::PhpResource,
- question: &Question,
+ question: &impl QuestionInterface,
) -> PhpMixed {
if !question.is_multiline() {
let cp = self.set_io_codepage();
@@ -869,11 +869,6 @@ impl QuestionHelper {
}
}
-/// Downcasts a Question to a ChoiceQuestion if applicable.
-fn question_as_choice_question(question: &Question) -> Option<&ChoiceQuestion> {
- question.as_any().downcast_ref::<ChoiceQuestion>()
-}
-
// PHP `__FILE__` magic constant. The shim's `file()` is PHP's file() function,
// not the magic constant, and there is no `__FILE__` shim yet (see report).
fn magic_file() -> String {
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
index c1d8455..9940896 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
@@ -4,9 +4,7 @@ use crate::symfony::console::formatter::output_formatter::OutputFormatter;
use crate::symfony::console::helper::question_helper::QuestionHelper;
use crate::symfony::console::output::output_interface;
use crate::symfony::console::output::output_interface::OutputInterface;
-use crate::symfony::console::question::choice_question::ChoiceQuestion;
-use crate::symfony::console::question::confirmation_question::ConfirmationQuestion;
-use crate::symfony::console::question::question::Question;
+use crate::symfony::console::question::QuestionInterface;
use crate::symfony::console::style::symfony_style::SymfonyStyle;
use shirabe_php_shim::AsAny;
use shirabe_php_shim::PhpMixed;
@@ -28,7 +26,7 @@ impl SymfonyQuestionHelper {
pub(crate) fn write_prompt(
&self,
output: Rc<RefCell<dyn OutputInterface>>,
- question: &Question,
+ question: &impl QuestionInterface,
) {
let mut text = OutputFormatter::escape_trailing_backslash(question.get_question());
let default = question.get_default();
@@ -43,11 +41,7 @@ impl SymfonyQuestionHelper {
// switch (true)
if matches!(default, PhpMixed::Null) {
text = format!(" <info>{}</info>:", PhpMixed::String(text));
- } else if question
- .as_any()
- .downcast_ref::<ConfirmationQuestion>()
- .is_some()
- {
+ } else if question.as_confirmation().is_some() {
text = format!(
" <info>{} (yes/no)</info> [<comment>{}</comment>]:",
PhpMixed::String(text),
@@ -60,11 +54,7 @@ impl SymfonyQuestionHelper {
.to_string(),
),
);
- } else if let Some(choice_question) = question
- .as_any()
- .downcast_ref::<ChoiceQuestion>()
- .filter(|q| q.is_multiselect())
- {
+ } else if let Some(choice_question) = question.as_choice().filter(|q| q.is_multiselect()) {
let choices = choice_question.get_choices();
let default_parts = shirabe_php_shim::explode(",", &default.to_string());
@@ -83,7 +73,7 @@ impl SymfonyQuestionHelper {
PhpMixed::String(text),
PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()),
);
- } else if let Some(choice_question) = question.as_any().downcast_ref::<ChoiceQuestion>() {
+ } else if let Some(choice_question) = question.as_choice() {
let choices = choice_question.get_choices();
text = format!(
" <info>{}</info> [<comment>{}</comment>]:",
@@ -113,7 +103,7 @@ impl SymfonyQuestionHelper {
let mut prompt = " > ".to_string();
- if let Some(choice_question) = question.as_any().downcast_ref::<ChoiceQuestion>() {
+ if let Some(choice_question) = question.as_choice() {
output.borrow().writeln(
&self
.inner