From 8db3f690cf86552cbc69f98df4cd5584368e5981 Mon Sep 17 00:00:00 2001 From: Stephan Huber Date: Thu, 13 Apr 2023 22:53:48 +0200 Subject: [PATCH] feat: Allow an about section for scaffolding files --- src/Scaffolder/Scaffolder.php | 4 ++++ src/Utilities/QuestionFactory.php | 4 ++-- src/Utilities/Questions/QuestionBase.php | 5 +++++ src/Utilities/Questions/QuestionInterface.php | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Scaffolder/Scaffolder.php b/src/Scaffolder/Scaffolder.php index ab654f2a..9bdf366b 100644 --- a/src/Scaffolder/Scaffolder.php +++ b/src/Scaffolder/Scaffolder.php @@ -229,6 +229,10 @@ public function scaffold( $tokens = Utilities::mergeData($this->readTokens($root_folder, $tokens['name']), $tokens); } + if ($data['about']) { + $io->block($data['about'], null, 'fg=yellow', ' ', true); + } + $questions = !empty($data['questions']) ? $data['questions'] : []; $tokens = $this->askQuestions($questions, $context, $tokens, $options); if (!empty($data['variables'])) { diff --git a/src/Utilities/QuestionFactory.php b/src/Utilities/QuestionFactory.php index 496d6ddc..21af2b47 100644 --- a/src/Utilities/QuestionFactory.php +++ b/src/Utilities/QuestionFactory.php @@ -42,8 +42,8 @@ public function askAndValidate(SymfonyStyle $io, $question_data, $value) } if (is_null($value)) { - if (!empty($question_data['help'])) { - $io->comment($question_data['help']); + if ($help_msg = $question_wrapper->getHelp()) { + $io->comment($help_msg); } $value = $question_wrapper->ask($io); } diff --git a/src/Utilities/Questions/QuestionBase.php b/src/Utilities/Questions/QuestionBase.php index bf224429..9c68fbe9 100644 --- a/src/Utilities/Questions/QuestionBase.php +++ b/src/Utilities/Questions/QuestionBase.php @@ -31,4 +31,9 @@ public function validate($value) } return $value; } + + public function getHelp() + { + return $this->data['help'] ?? false; + } } diff --git a/src/Utilities/Questions/QuestionInterface.php b/src/Utilities/Questions/QuestionInterface.php index b6372288..260542c9 100644 --- a/src/Utilities/Questions/QuestionInterface.php +++ b/src/Utilities/Questions/QuestionInterface.php @@ -12,6 +12,8 @@ public static function getName(); public function setData($question_data): ValidationService; public function ask(SymfonyStyle $io); - + public function validate($value); + + public function getHelp(); }