From 723d5802520ae2cbd402fdfebd35c61ed178a0ab Mon Sep 17 00:00:00 2001 From: Nikolay Lobachev Date: Sat, 20 Jan 2018 23:22:48 +0100 Subject: [PATCH] Add new trait ArrayInputTrait, which will parse nested data. Switch muti value options to array to handle them properly, when receive params through the options (#3712) --- src/Command/Generate/ThemeCommand.php | 28 ++++++++++++---- src/Command/Shared/ArrayInputTrait.php | 45 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/Command/Shared/ArrayInputTrait.php diff --git a/src/Command/Generate/ThemeCommand.php b/src/Command/Generate/ThemeCommand.php index 990d4908c..104676b1b 100644 --- a/src/Command/Generate/ThemeCommand.php +++ b/src/Command/Generate/ThemeCommand.php @@ -7,6 +7,7 @@ namespace Drupal\Console\Command\Generate; +use Drupal\Console\Command\Shared\ArrayInputTrait; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -32,6 +33,7 @@ class ThemeCommand extends Command use ConfirmationTrait; use ThemeRegionTrait; use ThemeBreakpointTrait; + use ArrayInputTrait; /** * @var Manager @@ -148,7 +150,7 @@ protected function configure() ->addOption( 'libraries', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.generate.theme.options.libraries') ) ->addOption( @@ -160,13 +162,13 @@ protected function configure() ->addOption( 'regions', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.generate.theme.options.regions') ) ->addOption( 'breakpoints', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.generate.theme.options.breakpoints') ) ->setAliases(['gt']); @@ -199,6 +201,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $libraries = $input->getOption('libraries'); $regions = $input->getOption('regions'); $breakpoints = $input->getOption('breakpoints'); + $noInteraction = $input->getOption('no-interaction'); + + // Parse nested data. + if ($noInteraction) { + $libraries = $this->explodeInlineArray($libraries); + $regions = $this->explodeInlineArray($regions); + $breakpoints = $this->explodeInlineArray($breakpoints); + } $this->generator->generate( $theme, @@ -345,9 +355,11 @@ function ($theme_path) use ($machine_name) { ) { // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::libraryQuestion $libraries = $this->libraryQuestion(); - $input->setOption('libraries', $libraries); } + } else { + $libraries = $this->explodeInlineArray($libraries); } + $input->setOption('libraries', $libraries); // --regions option. $regions = $input->getOption('regions'); @@ -359,9 +371,11 @@ function ($theme_path) use ($machine_name) { ) { // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion $regions = $this->regionQuestion(); - $input->setOption('regions', $regions); } + } else { + $regions = $this->explodeInlineArray($regions); } + $input->setOption('regions', $regions); // --breakpoints option. $breakpoints = $input->getOption('breakpoints'); @@ -373,8 +387,10 @@ function ($theme_path) use ($machine_name) { ) { // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion $breakpoints = $this->breakpointQuestion(); - $input->setOption('breakpoints', $breakpoints); } + } else { + $breakpoints = $this->explodeInlineArray($breakpoints); } + $input->setOption('breakpoints', $breakpoints); } } diff --git a/src/Command/Shared/ArrayInputTrait.php b/src/Command/Shared/ArrayInputTrait.php new file mode 100644 index 000000000..a6a016170 --- /dev/null +++ b/src/Command/Shared/ArrayInputTrait.php @@ -0,0 +1,45 @@ +