drush / example-drush-extension
Example Drush site-wide extension
Installs: 56
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 6
Forks: 2
Open Issues: 2
Type:drupal-drush
Requires
- php: >=5.6
- consolidation/site-alias: ^3.0.0@stable
- consolidation/site-process: ^2.0.0@stable
Requires (Dev)
- composer/installers: ^1.2
- drupal-composer/drupal-scaffold: ^2.5
- drupal/core: ^8.7
- drush/drush: ^8.2.2 || ^9.6.1
- g1a/composer-test-scenarios: ^3.0.2
- phpunit/phpunit: ^6.5
- symfony/filesystem: ^3.4.28
- webflo/drupal-finder: ^1.1.0
- webmozart/path-util: ^2.3
- zaporylie/composer-drupal-optimizations: ^1.0.2
This package is auto-updated.
Last update: 2024-10-29 05:40:40 UTC
README
This is an example Drush extension that is compatible with both Drush 9.6+ and Drush 8.2+. It includes tests that run on both versions of Drush.
This this project demonstrates what is known as a "site-wide" Drush extension. Site-wide extensions are installed via Composer into a particular Drupal site. The other kinds of Drush extensions are Drush module commands and Drush global commands. See the Creating Custom Drush Commands documentation for more information.
For maximum compatibility with future versions of Drush, a site-wide Drush extension should only call the following APIs:
- APIs provided by Drupal
- APIs provided by Drupal's dependencies
- Libraries decleared in the site-wide extension's own composer.json file
Avoid using Drush APIs, save for those that are defined by your command's base class, DrushCommands, or those that are provided by objects injected into your command class by Drush. See ExampleCommands.php for examples.
Usage
In development, clone this repository, then set up the System Under Test (sut) via:
composer install
composer drupal:scaffold
That will set up your local project to run and test with Drush 9. To use Drush 8 instead:
composer scenario drush8
The Composer Test Scenarios project is used to manage the Composer dependencies needed to test different scenarios of this project. Running composer scenario
is like running composer install
; it will install the appropriate dependencies for the requested testing scenario. Run composer install
to return to the default installation.
To use this extension in production (that is, to install it in a Drupal 8 site):
cd /path/to/my-drupal-composer-drupal-project
composer require drush/example-drush-extension
Running Tests
Set up for 'development' as described in usage section. Then, run:
composer test
Ad-hoc Testing
In development:
composer drush example:param test
In production:
cd /path/to/my-drupal-composer-drupal-project
drush example:param test
Customizing
- Fork this repository.
- Alter "name", "description" and etc. in composer.json to suit.
- Rename ExampleCommands.php and ExampleCommandsTest.php for your project.
- Configuration and site aliases for use in testing can be placed in 'sut/drush/drush.yml' and 'sut/drush/sites/self.site.yml', respectively.
- Examine 'sut/drush/drush.yml' and 'sut/drush/drushrc.php', and alter the names of the example command files to match the names in your project. This is necessary for Drush to be able to find your command files when running tests or doing ad-hoc testing, as usually, command files are searched for in the parent directory of the project root.
- Add your extension on packagist.org so that it may be installed via Composer.