Skip to content

Commit

Permalink
another way
Browse files Browse the repository at this point in the history
  • Loading branch information
ol0lll committed Aug 26, 2024
1 parent ba8d688 commit 4e4bef4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
67 changes: 63 additions & 4 deletions BackendCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**

Check failure on line 52 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Doc comment for parameter "$command" missing

Check failure on line 52 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Doc comment for parameter "$annotationData" missing
* 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

Check failure on line 59 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Doc comment for parameter $options does not match actual variable name $command
*/
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.
*
Expand Down Expand Up @@ -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',
Expand All @@ -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);
}
Expand Down
14 changes: 2 additions & 12 deletions BackendCommandsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 4e4bef4

Please sign in to comment.