diff --git a/BackendCommands.php b/BackendCommands.php index b67187b..60d1703 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -38,6 +38,36 @@ public function __construct() $this->filesystem = new Filesystem(); } + /** + * @hook init @options-backend + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function initCommands(InputInterface $input, AnnotationData $annotationData) + { + $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); + } + + /** + * Define default options for most backend commands. + * + * @hook option @options-backend + * + * @option project-directory The base directory of the project. Defaults to composer root of project. + * + * @param array $options + */ + public function optionsBackend(Command $command, AnnotationData $annotationData) + { + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); + } + /** * Prepare file system and code to be ready for install. * @@ -127,12 +157,41 @@ public function updateDatabase() /** * Add option to command. * - * @hook option backend:create-testing-dump backend:install config:export config:import + * @hook option config:export + * + * @param \Symfony\Component\Console\Command\Command $command + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function additionalConfigExportOptions(Command $command, AnnotationData $annotationData) + { + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); + } + + /** + * @hook init config:export + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function initConfigExportCommands(InputInterface $input, AnnotationData $annotationData) + { + $this->initCommands($input, $annotationData); + } + + /** + * Add option to command. + * + * @hook option config:import * * @param \Symfony\Component\Console\Command\Command $command * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function additionalBackendOptions(Command $command, AnnotationData $annotationData) + public function additionalConfigImportOptions(Command $command, AnnotationData $annotationData) { $command->addOption( 'project-directory', @@ -143,12 +202,12 @@ public function additionalBackendOptions(Command $command, AnnotationData $annot } /** - * @hook init backend:create-testing-dump backend:install config:export config:import + * @hook init config:import * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function initBackendCommands(InputInterface $input, AnnotationData $annotationData) + public function initConfigImportCommands(InputInterface $input, AnnotationData $annotationData) { $this->initCommands($input, $annotationData); } diff --git a/BackendCommandsTrait.php b/BackendCommandsTrait.php index c14532b..c7141c7 100644 --- a/BackendCommandsTrait.php +++ b/BackendCommandsTrait.php @@ -7,7 +7,9 @@ use Consolidation\SiteAlias\SiteAliasManagerAwareTrait; use Drupal\Core\Site\Settings; use Drush\Drush; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Filesystem\Path; /** @@ -36,18 +38,6 @@ trait BackendCommandsTrait */ private $projectDirectory; - /** - * Init params. - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData - */ - public function initCommands(InputInterface $input, AnnotationData $annotationData) - { - // Initialize project directory. - $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); - } - /** * Drush command wrapper. *