diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-12 01:01:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-12 01:01:43 +0900 |
| commit | 1e44f5723e4c0e0903d00a61f254901e612fe5e1 (patch) | |
| tree | 9c2e1eec364bbf6418a4072ee7767b04c3df0297 /crates/shirabe/src/question/strict_confirmation_question.rs | |
| parent | ddf0a624145b618c05c2ee47414545b99b685f37 (diff) | |
| download | php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.tar.gz php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.tar.zst php-shirabe-1e44f5723e4c0e0903d00a61f254901e612fe5e1.zip | |
feat(symfony-console): port Symfony Console and make the workspace compile
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/question/strict_confirmation_question.rs')
| -rw-r--r-- | crates/shirabe/src/question/strict_confirmation_question.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/crates/shirabe/src/question/strict_confirmation_question.rs b/crates/shirabe/src/question/strict_confirmation_question.rs index 5ce32f2..725005a 100644 --- a/crates/shirabe/src/question/strict_confirmation_question.rs +++ b/crates/shirabe/src/question/strict_confirmation_question.rs @@ -1,6 +1,5 @@ //! ref: composer/src/Composer/Question/StrictConfirmationQuestion.php -use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::exception::InvalidArgumentException; use shirabe_external_packages::symfony::console::question::Question; @@ -19,7 +18,7 @@ impl StrictConfirmationQuestion { true_answer_regex: String, false_answer_regex: String, ) -> Self { - let inner = Question::new(&question, Some(PhpMixed::Bool(default))); + let inner = Question::new(question, Some(PhpMixed::Bool(default))); let mut this = Self { inner, true_answer_regex, @@ -36,19 +35,19 @@ impl StrictConfirmationQuestion { &self.inner } - fn get_default_normalizer(&self) -> Box<dyn Fn(&PhpMixed) -> PhpMixed> { + fn get_default_normalizer(&self) -> Box<dyn Fn(PhpMixed) -> PhpMixed> { let default = self.inner.get_default(); let true_regex = self.true_answer_regex.clone(); let false_regex = self.false_answer_regex.clone(); - Box::new(move |answer: &PhpMixed| { - if is_bool(answer) { - return answer.clone(); + Box::new(move |answer: PhpMixed| { + if is_bool(&answer) { + return answer; } - if empty(answer) && default.as_ref().is_some_and(|d| !empty(d)) { - return default.clone().unwrap_or(PhpMixed::Null); + if empty(&answer) && !empty(&default) { + return default.clone(); } - if let PhpMixed::String(s) = answer { + if let PhpMixed::String(s) = &answer { if Preg::is_match(&true_regex, s).unwrap_or(false) { return PhpMixed::Bool(true); } @@ -60,15 +59,18 @@ impl StrictConfirmationQuestion { }) } - fn get_default_validator(&self) -> Box<dyn Fn(Option<PhpMixed>) -> Result<PhpMixed>> { + fn get_default_validator( + &self, + ) -> Box<dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>> { Box::new(|answer: Option<PhpMixed>| { let answer = answer.unwrap_or(PhpMixed::Null); if !is_bool(&answer) { - return Err(InvalidArgumentException { - message: "Please answer yes, y, no, or n.".to_string(), - code: 0, - } - .into()); + return Err(InvalidArgumentException( + shirabe_php_shim::InvalidArgumentException { + message: "Please answer yes, y, no, or n.".to_string(), + code: 0, + }, + )); } Ok(answer) }) |
