├── test ├── .gitkeep ├── fixtures │ └── sites.valid.php ├── Unit │ ├── Trait │ │ ├── DrupalFinderAwareTraitTest.php │ │ └── SiteDetectorAwareTraitTest.php │ ├── TestCaseTest.php │ ├── Model │ │ ├── SiteDetectorOptionsTest.php │ │ ├── PlaceholderTest.php │ │ └── SitesFileTest.php │ ├── DrallTest.php │ └── Service │ │ └── SiteDetectorTest.php └── Integration │ ├── DrallTest.php │ └── Command │ ├── SiteDirectoriesCommandTest.php │ ├── SiteAliasesCommandTest.php │ ├── BaseCommandTest.php │ ├── SiteKeysCommandTest.php │ └── ExecCommandTest.php ├── .docker ├── main │ ├── empty-drupal │ │ ├── web │ │ │ └── sites │ │ │ │ └── sites.php │ │ └── composer.json │ ├── .profile │ ├── drupal │ │ ├── drush │ │ │ └── sites │ │ │ │ ├── tmnt.site.yml │ │ │ │ ├── leo.site.yml │ │ │ │ ├── ralph.site.yml │ │ │ │ ├── donnie.site.yml │ │ │ │ └── mikey.site.yml │ │ ├── web │ │ │ └── sites │ │ │ │ ├── sites.bad.php │ │ │ │ ├── sites.reddish.php │ │ │ │ ├── sites.bluish.php │ │ │ │ └── sites.php │ │ └── composer.json │ ├── no-drupal │ │ └── composer.json │ └── Dockerfile └── database │ └── init.sql ├── .gitignore ├── misc ├── demo.gif ├── drall.v1.png ├── drall.v2.png └── example.sites.php ├── src ├── Exception │ ├── PlaceholderException.php │ └── DrallException.php ├── Trait │ ├── DrupalFinderAwareTrait.php │ └── SiteDetectorAwareTrait.php ├── Command │ ├── SiteKeysCommand.php │ ├── SiteDirectoriesCommand.php │ ├── SiteAliasesCommand.php │ ├── BaseCommand.php │ └── ExecCommand.php ├── Model │ ├── SitesFile.php │ ├── Placeholder.php │ └── SiteDetectorOptions.php ├── TestCase.php ├── Drall.php └── Service │ └── SiteDetector.php ├── .editorconfig ├── bin ├── drall ├── drall-launcher └── drush-launcher ├── grumphp.yml ├── docker-compose.yml ├── .github └── workflows │ └── validation.yml ├── phpunit.xml ├── phpcs.xml ├── composer.json ├── Makefile ├── README.md └── LICENSE /test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.docker/main/empty-drupal/web/sites/sites.php: -------------------------------------------------------------------------------- 1 | setAutoExit(TRUE); 19 | $drall->run(); 20 | -------------------------------------------------------------------------------- /bin/drall-launcher: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | dir=$(pwd) 6 | while [ "$dir" != "/" ]; do 7 | if [ -x "$dir/vendor/bin/drall" ]; then 8 | "$dir/vendor/bin/drall" "$@" 9 | break 10 | fi 11 | dir=$(dirname "$dir") 12 | done 13 | 14 | if [ "$dir" == "/" ]; then 15 | echo "Drall executable not found." 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /bin/drush-launcher: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | dir=$(pwd) 6 | while [ "$dir" != "/" ]; do 7 | if [ -x "$dir/vendor/bin/drush" ]; then 8 | "$dir/vendor/bin/drush" "$@" 9 | break 10 | fi 11 | dir=$(dirname "$dir") 12 | done 13 | 14 | if [ "$dir" == "/" ]; then 15 | echo "Drush executable not found." 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /.docker/main/drupal/web/sites/sites.bluish.php: -------------------------------------------------------------------------------- 1 | > /root/.profile 22 | RUN echo ". /opt/drall/.docker/main/.profile" >> /root/.bashrc 23 | -------------------------------------------------------------------------------- /test/Unit/Trait/DrupalFinderAwareTraitTest.php: -------------------------------------------------------------------------------- 1 | getMockForTrait(DrupalFinderAwareTrait::class); 14 | $drupalFinder = new DrupalFinderComposerRuntime(); 15 | $subject->setDrupalFinder($drupalFinder); 16 | 17 | $this->assertSame($drupalFinder, $subject->drupalFinder()); 18 | } 19 | 20 | public function testDrupalFinderNotSet() { 21 | $this->expectException(\BadMethodCallException::class); 22 | $subject = $this->getMockForTrait(DrupalFinderAwareTrait::class); 23 | $subject->drupalFinder(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | main: 3 | image: drupal:drall 4 | container_name: drall-main 5 | build: 6 | context: . 7 | dockerfile: .docker/main/Dockerfile 8 | depends_on: 9 | - database 10 | ports: 11 | - "8080:80" 12 | volumes: 13 | - .:/opt/drall 14 | - .docker/main/drupal/composer.json:/opt/drupal/composer.json 15 | - ./Makefile:/opt/no-drupal/Makefile 16 | - ./Makefile:/opt/empty-drupal/Makefile 17 | - ./Makefile:/opt/drupal/Makefile 18 | environment: 19 | - DRALL_ENVIRONMENT=development 20 | 21 | database: 22 | image: mariadb:10 23 | container_name: drall-db 24 | environment: 25 | MARIADB_USER: drupal 26 | MARIADB_PASSWORD: drupal 27 | MARIADB_ROOT_PASSWORD: drupal 28 | volumes: 29 | - .docker/database/init.sql:/docker-entrypoint-initdb.d/1-init.sql 30 | -------------------------------------------------------------------------------- /test/Unit/Trait/SiteDetectorAwareTraitTest.php: -------------------------------------------------------------------------------- 1 | getMockForTrait(SiteDetectorAwareTrait::class); 20 | $subject->setSiteDetector($siteDetector); 21 | 22 | $this->assertSame($siteDetector, $subject->siteDetector()); 23 | } 24 | 25 | public function testSiteDetectorNotSet() { 26 | $this->expectException(\BadMethodCallException::class); 27 | $subject = $this->getMockForTrait(SiteDetectorAwareTrait::class); 28 | $subject->siteDetector(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Trait/DrupalFinderAwareTrait.php: -------------------------------------------------------------------------------- 1 | drupalFinder = $drupalFinder; 19 | } 20 | 21 | /** 22 | * Get a Drupal finder. 23 | * 24 | * @return \DrupalFinder\DrupalFinder 25 | * A Drupal Finder. 26 | * 27 | * @throws \BadMethodCallException 28 | */ 29 | public function drupalFinder(): DrupalFinderComposerRuntime { 30 | if (!$this->hasDrupalFinder()) { 31 | throw new \BadMethodCallException( 32 | 'A Drupal Finder instance must first be assigned' 33 | ); 34 | } 35 | 36 | return $this->drupalFinder; 37 | } 38 | 39 | /** 40 | * Whether the instance has a Drupal Finder attached. 41 | * 42 | * @return bool 43 | * TRUE or FALSE. 44 | */ 45 | protected function hasDrupalFinder(): bool { 46 | return isset($this->drupalFinder); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/Trait/SiteDetectorAwareTrait.php: -------------------------------------------------------------------------------- 1 | siteDetector = $siteDetector; 22 | } 23 | 24 | /** 25 | * Get a site detector. 26 | * 27 | * @return \Drall\Service\SiteDetector 28 | * A site detector. 29 | */ 30 | public function siteDetector(): SiteDetector { 31 | if (!$this->hasSiteDetector()) { 32 | throw new \BadMethodCallException( 33 | 'A site detector instance must first be assigned' 34 | ); 35 | } 36 | 37 | return $this->siteDetector; 38 | } 39 | 40 | /** 41 | * Whether the instance has a Site Detector attached. 42 | * 43 | * @return bool 44 | * TRUE or FALSE. 45 | */ 46 | protected function hasSiteDetector(): bool { 47 | return isset($this->siteDetector); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /.github/workflows/validation.yml: -------------------------------------------------------------------------------- 1 | name: validation 2 | on: 3 | - push 4 | env: 5 | DRUPAL_PATH: /opt/drupal 6 | jobs: 7 | test: 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: ['ubuntu-latest'] 12 | php-versions: ['8.3', '8.4'] 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: shivammathur/setup-php@v2 16 | with: 17 | php-version: ${{ matrix.php-versions }} 18 | - name: Determine Composer Cache Directory 19 | id: composer-cache 20 | run: | 21 | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT 22 | - uses: actions/cache@v3 23 | with: 24 | path: ${{ steps.composer-cache.outputs.dir }} 25 | key: ${{ runner.os }}-composer-${{ hashFiles('/opt/*/composer.lock') }} 26 | restore-keys: | 27 | ${{ runner.os }}-composer- 28 | - name: Prepare 29 | run: | 30 | cp -r . /opt/drall 31 | make provision 32 | - name: Info 33 | run: make info 34 | - name: Lint 35 | run: make lint 36 | - name: Test 37 | run: make test 38 | - name: Coverage 39 | run: make coverage-report/text 40 | -------------------------------------------------------------------------------- /src/Command/SiteKeysCommand.php: -------------------------------------------------------------------------------- 1 | addUsage('site:keys'); 20 | $this->addUsage('--group=GROUP site:keys'); 21 | $this->addUsage('--filter=FILTER site:keys'); 22 | } 23 | 24 | protected function execute(InputInterface $input, OutputInterface $output): int { 25 | $this->preExecute($input, $output); 26 | 27 | $sdOptions = SiteDetectorOptions::fromInput($input); 28 | $keys = $this->siteDetector() 29 | ->getSiteKeys($sdOptions); 30 | 31 | if (count($keys) === 0) { 32 | $this->logger->warning('No Drupal sites found.'); 33 | return 0; 34 | } 35 | 36 | foreach ($keys as $key) { 37 | $output->writeln($key); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Command/SiteDirectoriesCommand.php: -------------------------------------------------------------------------------- 1 | addUsage('site:directories'); 20 | $this->addUsage('--group=GROUP site:directories'); 21 | } 22 | 23 | protected function execute(InputInterface $input, OutputInterface $output): int { 24 | $this->preExecute($input, $output); 25 | 26 | $sdOptions = SiteDetectorOptions::fromInput($input); 27 | $dirNames = $this->siteDetector() 28 | ->getSiteDirNames($sdOptions); 29 | 30 | if (count($dirNames) === 0) { 31 | $this->logger->warning('No Drupal sites found.'); 32 | return 0; 33 | } 34 | 35 | foreach ($dirNames as $dirName) { 36 | $output->writeln($dirName); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/Command/SiteAliasesCommand.php: -------------------------------------------------------------------------------- 1 | addUsage('site:aliases'); 20 | $this->addUsage('--group=GROUP site:aliases'); 21 | $this->addUsage('--filter=FILTER site:aliases'); 22 | } 23 | 24 | protected function execute(InputInterface $input, OutputInterface $output): int { 25 | $this->preExecute($input, $output); 26 | 27 | $sdOptions = SiteDetectorOptions::fromInput($input); 28 | $aliases = $this->siteDetector() 29 | ->getSiteAliases($sdOptions); 30 | 31 | if (count($aliases) === 0) { 32 | $this->logger->warning('No site aliases found.'); 33 | return 0; 34 | } 35 | 36 | foreach ($aliases as $alias) { 37 | $output->writeln($alias); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /test/Integration/DrallTest.php: -------------------------------------------------------------------------------- 1 | run(); 21 | $version = InstalledVersions::getPrettyVersion('jigarius/drall'); 22 | $this->assertStringContainsString(Drall::NAME . ' ' . $version, $process->getOutput()); 23 | } 24 | 25 | /** 26 | * @testdox Suggests "drush" for unrecognized commands. 27 | */ 28 | public function testUnrecognizedCommand(): void { 29 | $process = Process::fromShellCommandline('drall st', static::PATH_DRUPAL); 30 | $process->run(); 31 | $this->assertOutputEquals(<<getErrorOutput()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | test 20 | 21 | 22 | 24 | 25 | src 26 | 27 | 28 | 30 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A coding standard for Drall. 4 | . 5 | dev/* 6 | .phpunit.cache/* 7 | vendor/* 8 | 9 | 10 | 11 | 12 | ./vendor/autoload.php 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 0 34 | 35 | 36 | 0 37 | 38 | 39 | test/*.php 40 | 41 | 42 | test/*.php 43 | 44 | 45 | -------------------------------------------------------------------------------- /test/Unit/TestCaseTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(sys_get_temp_dir(), dirname($path)); 15 | $this->assertStringStartsWith('Drall.', basename($path)); 16 | } 17 | 18 | public function testCreateTempFile() { 19 | $path = static::createTempFile('Bunny Wabbit'); 20 | $this->assertFileExists($path); 21 | $this->assertEquals('Bunny Wabbit', file_get_contents($path)); 22 | } 23 | 24 | public function testAssertOutputEquals() { 25 | // For some reason, drush's output ($actual) has spaces before EOL. 26 | // This assertion respects leading spaces and ignores trailing spaces. 27 | $this->assertOutputEquals(<<assertOutputStartsWith( 39 | '[notice] Hakuna matata.' . PHP_EOL, 40 | "[notice] Hakuna matata. \n - bunny \n - wabbit \n", 41 | ); 42 | } 43 | 44 | public function testAssertOutputContainsString() { 45 | // For some reason, drush's output ($actual) has spaces before EOL. 46 | // This assertion respects leading spaces and ignores trailing spaces. 47 | $this->assertOutputContainsString( 48 | ' - bunny' . PHP_EOL, 49 | "[notice] Hakuna matata. \n - bunny \n - wabbit \n", 50 | ); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Model/SitesFile.php: -------------------------------------------------------------------------------- 1 | path = $path; 16 | $this->entries = $this->getEntries(); 17 | } 18 | 19 | /** 20 | * Get the path to the sites file. 21 | * 22 | * @return string 23 | * Path to the file. 24 | */ 25 | public function getPath(): string { 26 | return $this->path; 27 | } 28 | 29 | /** 30 | * Get the value of the $sites variable. 31 | * 32 | * @return array 33 | * Contents of the $sites array. 34 | */ 35 | private function getEntries(): array { 36 | if (!is_file($this->path)) { 37 | throw new \RuntimeException("Cannot read sites file: $this->path"); 38 | } 39 | 40 | require $this->path; 41 | 42 | if (!isset($sites) || !is_array($sites)) { 43 | throw new \RuntimeException("Site declarations not found in file: $this->path"); 44 | } 45 | 46 | return $sites; 47 | } 48 | 49 | /** 50 | * Get an array of site directory names. 51 | * 52 | * @return array 53 | * Site directory names. 54 | */ 55 | public function getDirNames(): array { 56 | return array_values(array_unique($this->entries)); 57 | } 58 | 59 | /** 60 | * Get keys of the $sites array. 61 | * 62 | * @param bool $unique 63 | * If TRUE, only one key (the last one) will be returned for each site. 64 | * 65 | * @return array 66 | * Site keys from $sites. 67 | */ 68 | public function getKeys(bool $unique = FALSE): array { 69 | if (!$unique) { 70 | return array_keys($this->entries); 71 | } 72 | 73 | return array_keys(array_flip(array_flip($this->entries))); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jigarius/drall", 3 | "description": "Drall is a command-line utility to run drush on multi-site Drupal installations.", 4 | "license": "GPL-3.0-only", 5 | "keywords": [ 6 | "drupal", 7 | "drush", 8 | "drall", 9 | "cli" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Jerry Radwick", 14 | "homepage": "https://jigarius.com/", 15 | "role": "Developer" 16 | } 17 | ], 18 | "homepage": "https://github.com/jigarius/drall", 19 | "require": { 20 | "php": ">= 8.3", 21 | "amphp/pipeline": "^1.2", 22 | "amphp/process": "^2", 23 | "consolidation/filter-via-dot-access-data": "^2.0", 24 | "consolidation/site-alias": "^3 || ^4", 25 | "drush/drush": "^12 || ^13", 26 | "webflo/drupal-finder": "^1.2" 27 | }, 28 | "require-dev": { 29 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", 30 | "drupal/coder": "^8.3", 31 | "ergebnis/composer-normalize": "^2.28", 32 | "phpro/grumphp": "^2.10", 33 | "phpunit/phpunit": "^9.5", 34 | "squizlabs/php_codesniffer": "^3.6" 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "Drall\\": "src/" 39 | }, 40 | "classmap": [ 41 | "src/Drall.php" 42 | ] 43 | }, 44 | "bin": [ 45 | "bin/drall" 46 | ], 47 | "config": { 48 | "allow-plugins": { 49 | "dealerdirect/phpcodesniffer-composer-installer": true, 50 | "ergebnis/composer-normalize": true, 51 | "phpro/grumphp": true 52 | }, 53 | "sort-packages": true 54 | }, 55 | "extra": { 56 | "phpcodesniffer-search-depth": 5 57 | }, 58 | "scripts": { 59 | "lint": "composer exec phpcs", 60 | "test": "XDEBUG_MODE=coverage composer exec phpunit" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Model/Placeholder.php: -------------------------------------------------------------------------------- 1 | value)\b/"; 22 | } 23 | 24 | /** 25 | * Detect all valid placeholders present in a string. 26 | * 27 | * @param string $haystack 28 | * A string. 29 | * 30 | * @return \Drall\Model\Placeholder[] 31 | * All placeholders that were found (if any). 32 | */ 33 | public static function search(string $haystack): array { 34 | $result = array_filter(self::cases(), function ($p) use ($haystack) { 35 | return preg_match($p->getRegExp(), $haystack); 36 | }); 37 | 38 | return array_values($result); 39 | } 40 | 41 | /** 42 | * Replace placeholders with values in a given string. 43 | * 44 | * @param array $data 45 | * An array with @@placeholder as keys and replacements as values. 46 | * @param string $subject 47 | * The string on which to operate. 48 | * 49 | * @return string 50 | * The subject string with placeholders replaced with values. 51 | * 52 | * @todo Revisit when PHP allows enum as array keys. 53 | */ 54 | public static function replace(array $data, string $subject): string { 55 | $search = []; 56 | $replace = []; 57 | 58 | foreach ($data as $key => $value) { 59 | if (!$placeholder = Placeholder::tryFrom($key)) { 60 | continue; 61 | } 62 | 63 | $search[] = $placeholder->getRegExp(); 64 | $replace[] = $value; 65 | } 66 | 67 | return preg_replace($search, $replace, $subject); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /test/Unit/Model/SiteDetectorOptionsTest.php: -------------------------------------------------------------------------------- 1 | 'bluish', 14 | 'filter' => 'tnmt', 15 | ]); 16 | 17 | $this->assertEquals('bluish', $subject->getGroup()); 18 | $this->assertEquals('tnmt', $subject->getFilter()); 19 | } 20 | 21 | /** 22 | * @covers \Drall\Model\SiteDetectorOptions::setGroup() 23 | * @covers \Drall\Model\SiteDetectorOptions::getGroup() 24 | */ 25 | public function testGroup(): void { 26 | $subject = new SiteDetectorOptions(); 27 | $subject->setGroup('bluish'); 28 | $this->assertEquals('bluish', $subject->getGroup()); 29 | } 30 | 31 | /** 32 | * @covers \Drall\Model\SiteDetectorOptions::setFilter() 33 | * @covers \Drall\Model\SiteDetectorOptions::getFilter() 34 | */ 35 | public function testFilter(): void { 36 | $subject = new SiteDetectorOptions(); 37 | $subject->setFilter('tnmt'); 38 | $this->assertEquals('tnmt', $subject->getFilter()); 39 | } 40 | 41 | /** 42 | * @covers \Drall\Model\SiteDetectorOptions::setOffset() 43 | * @covers \Drall\Model\SiteDetectorOptions::getOffset() 44 | */ 45 | public function testOffset(): void { 46 | $subject = new SiteDetectorOptions(); 47 | $subject->setOffset(2); 48 | $this->assertEquals(2, $subject->getOffset()); 49 | } 50 | 51 | /** 52 | * @covers \Drall\Model\SiteDetectorOptions::setLimit() 53 | * @covers \Drall\Model\SiteDetectorOptions::getLimit() 54 | */ 55 | public function testLimit(): void { 56 | $subject = new SiteDetectorOptions(); 57 | $subject->setLimit(3); 58 | $this->assertEquals(3, $subject->getLimit()); 59 | 60 | // Negative limit throws an exception. 61 | $this->expectException(\ValueError::class); 62 | $this->expectExceptionMessage('Limit must be greater than zero.'); 63 | $subject->setLimit(-5); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /test/Unit/Model/PlaceholderTest.php: -------------------------------------------------------------------------------- 1 | assertEquals( 15 | [Placeholder::Site], 16 | Placeholder::search('drush @@site.local st') 17 | ); 18 | 19 | $this->assertEquals( 20 | [Placeholder::Directory], 21 | Placeholder::search('drush --uri=@@dir uli') 22 | ); 23 | 24 | $this->assertEquals( 25 | [Placeholder::Key], 26 | Placeholder::search('drush --uri=@@key uli') 27 | ); 28 | 29 | $this->assertEquals( 30 | [Placeholder::UniqueKey], 31 | Placeholder::search('drush --uri=@@ukey uli') 32 | ); 33 | } 34 | 35 | public function testWithUnrecognizedPlaceholder() { 36 | $this->assertEquals( 37 | [], 38 | Placeholder::search('drush --foo=@@bar st') 39 | ); 40 | } 41 | 42 | public function testReplace() { 43 | $this->assertEquals( 44 | 'drush @self.local st', 45 | Placeholder::replace(['@@site' => '@self'], 'drush @@site.local st') 46 | ); 47 | 48 | $this->assertEquals( 49 | 'drush --uri=default uli', 50 | Placeholder::replace(['@@dir' => 'default'], 'drush --uri=@@dir uli') 51 | ); 52 | 53 | $this->assertEquals( 54 | 'drush --uri=example.com uli', 55 | Placeholder::replace(['@@key' => 'example.com'], 'drush --uri=@@key uli') 56 | ); 57 | 58 | $this->assertEquals( 59 | 'drush --uri=example.com uli', 60 | Placeholder::replace(['@@ukey' => 'example.com'], 'drush --uri=@@ukey uli') 61 | ); 62 | } 63 | 64 | public function testReplaceWithUnrecognizedPlaceholder() { 65 | $this->assertEquals( 66 | 'drush --foo=@@bar st', 67 | Placeholder::replace(['@@bar' => 'bar'], 'drush --foo=@@bar st') 68 | ); 69 | } 70 | 71 | public function testReplaceWithWordBoundary() { 72 | $this->assertEquals( 73 | 'Finished: @@directory', 74 | Placeholder::replace(['@@dir' => 'default'], 'Finished: @@directory') 75 | ); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/Command/BaseCommand.php: -------------------------------------------------------------------------------- 1 | addOption( 22 | 'group', 23 | 'g', 24 | InputOption::VALUE_OPTIONAL, 25 | 'Site group identifier.' 26 | ); 27 | 28 | $this->addOption( 29 | 'filter', 30 | 'f', 31 | InputOption::VALUE_OPTIONAL, 32 | 'Filter sites based on provided expression.' 33 | ); 34 | 35 | $this->addOption( 36 | 'offset', 37 | 'o', 38 | InputOption::VALUE_OPTIONAL, 39 | 'Number of items to skip.', 40 | 0, 41 | ); 42 | 43 | $this->addOption( 44 | 'limit', 45 | 'l', 46 | InputOption::VALUE_OPTIONAL, 47 | 'Number of items to process.', 48 | ); 49 | } 50 | 51 | protected function initialize(InputInterface $input, OutputInterface $output): void { 52 | if (!$this->logger) { 53 | $this->logger = new ConsoleLogger($output); 54 | } 55 | 56 | parent::initialize($input, $output); 57 | } 58 | 59 | protected function preExecute(InputInterface $input, OutputInterface $output) { 60 | if (!$this->hasSiteDetector()) { 61 | $this->setSiteDetector(new SiteDetector()); 62 | } 63 | 64 | $options = SiteDetectorOptions::fromInput($input); 65 | 66 | if ($group = $options->getGroup()) { 67 | $this->logger->info('Using group: {group}', ['group' => $group]); 68 | } 69 | 70 | if ($filter = $options->getFilter()) { 71 | $this->logger->info('Using filter: {filter}', ['filter' => $filter]); 72 | } 73 | 74 | if ($offset = $options->getOffset()) { 75 | $this->logger->info('Using offset: {offset}', ['offset' => $offset]); 76 | } 77 | 78 | if ($limit = $options->getLimit()) { 79 | $this->logger->info('Using limit: {limit}', ['limit' => $limit]); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /.docker/main/empty-drupal/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A Drupal installation with no sites.", 3 | "type": "project", 4 | "license": "GPL-2.0-or-later", 5 | "repositories": [ 6 | { 7 | "type": "composer", 8 | "url": "https://packages.drupal.org/8" 9 | }, 10 | { 11 | "type": "path", 12 | "url": "/opt/drall", 13 | "options": { 14 | "symlink": true 15 | } 16 | } 17 | ], 18 | "require": { 19 | "composer/installers": "^2", 20 | "drupal/core-composer-scaffold": "*", 21 | "drupal/core-recommended": "^11", 22 | "drupal/core-vendor-hardening": "*", 23 | "jigarius/drall": "*" 24 | }, 25 | "conflict": { 26 | "drupal/drupal": "*" 27 | }, 28 | "minimum-stability": "dev", 29 | "prefer-stable": true, 30 | "config": { 31 | "sort-packages": true, 32 | "allow-plugins": { 33 | "composer/installers": true, 34 | "drupal/core-composer-scaffold": true, 35 | "drupal/core-project-message": true, 36 | "drupal/core-vendor-hardening": true, 37 | "dealerdirect/phpcodesniffer-composer-installer": true 38 | } 39 | }, 40 | "extra": { 41 | "drupal-scaffold": { 42 | "locations": { 43 | "web-root": "web/" 44 | } 45 | }, 46 | "installer-paths": { 47 | "web/core": [ 48 | "type:drupal-core" 49 | ], 50 | "web/libraries/{$name}": [ 51 | "type:drupal-library" 52 | ], 53 | "web/modules/contrib/{$name}": [ 54 | "type:drupal-module" 55 | ], 56 | "web/profiles/contrib/{$name}": [ 57 | "type:drupal-profile" 58 | ], 59 | "web/themes/contrib/{$name}": [ 60 | "type:drupal-theme" 61 | ], 62 | "drush/Commands/contrib/{$name}": [ 63 | "type:drupal-drush" 64 | ], 65 | "web/modules/custom/{$name}": [ 66 | "type:drupal-custom-module" 67 | ], 68 | "web/profiles/custom/{$name}": [ 69 | "type:drupal-custom-profile" 70 | ], 71 | "web/themes/custom/{$name}": [ 72 | "type:drupal-custom-theme" 73 | ] 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/Unit/Model/SitesFileTest.php: -------------------------------------------------------------------------------- 1 | subject = new SitesFile(static::PATH_FIXTURES . '/sites.valid.php'); 15 | } 16 | 17 | public function testGetPath() { 18 | $this->assertEquals( 19 | static::PATH_FIXTURES . '/sites.valid.php', 20 | $this->subject->getPath() 21 | ); 22 | } 23 | 24 | public function testNonExistentPath() { 25 | $this->expectException(\RuntimeException::class); 26 | new SitesFile(static::PATH_FIXTURES . '/sites.non-existent.php'); 27 | } 28 | 29 | public function testSitesNotDefined() { 30 | $this->expectException(\RuntimeException::class); 31 | 32 | $path = $this->createTempFile('expectException(\RuntimeException::class); 38 | 39 | $path = $this->createTempFile('createTempFile('assertEmpty($subject->getDirNames()); 47 | } 48 | 49 | public function testGetDirNames() { 50 | $this->assertEquals( 51 | ['default', 'donnie', 'leo', 'mikey', 'ralph'], 52 | $this->subject->getDirNames() 53 | ); 54 | } 55 | 56 | public function testGetUris() { 57 | $this->assertEquals( 58 | [ 59 | 'tmnt.com', 60 | 'cowabunga.com', 61 | 'tmnt.drall.local', 62 | 'donatello.com', 63 | '8080.donatello.com', 64 | 'donnie.drall.local', 65 | 'leonardo.com', 66 | 'leo.drall.local', 67 | 'michelangelo.com', 68 | 'mikey.drall.local', 69 | 'raphael.com', 70 | 'ralph.drall.local', 71 | ], 72 | $this->subject->getKeys() 73 | ); 74 | } 75 | 76 | /** 77 | * Get unique URIs (the last one) for each site. 78 | */ 79 | public function testGetUniqueUris() { 80 | $this->assertEquals( 81 | [ 82 | 'tmnt.drall.local', 83 | 'donnie.drall.local', 84 | 'leo.drall.local', 85 | 'mikey.drall.local', 86 | 'ralph.drall.local', 87 | ], 88 | $this->subject->getKeys(TRUE) 89 | ); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /test/Integration/Command/SiteDirectoriesCommandTest.php: -------------------------------------------------------------------------------- 1 | run(); 20 | $this->assertStringContainsString('Package "drupal/core" is not installed', $process->getErrorOutput()); 21 | } 22 | 23 | /** 24 | * @testdox with an empty Drupal installation. 25 | */ 26 | public function testWithEmptyDrupal(): void { 27 | $process = Process::fromShellCommandline('drall site:directories', static::PATH_EMPTY_DRUPAL); 28 | $process->run(); 29 | $this->assertStringContainsString('[warning] No Drupal sites found.', $process->getOutput()); 30 | } 31 | 32 | /** 33 | * @testdox with a valid Drupal installation. 34 | */ 35 | public function testExecute(): void { 36 | $process = Process::fromShellCommandline('drall site:directories', static::PATH_DRUPAL); 37 | $process->run(); 38 | $this->assertOutputEquals(<<getOutput()); 46 | } 47 | 48 | /** 49 | * @testdox with --filter. 50 | */ 51 | public function testExecuteWithFilter(): void { 52 | $process = Process::fromShellCommandline('drall site:directories --filter="leo||ralph"', static::PATH_DRUPAL); 53 | $process->run(); 54 | $this->assertOutputEquals(<<getOutput()); 59 | } 60 | 61 | /** 62 | * @testdox with --group. 63 | */ 64 | public function testWithGroup(): void { 65 | $process = Process::fromShellCommandline('drall site:directories --group=bluish', static::PATH_DRUPAL); 66 | $process->run(); 67 | $this->assertOutputEquals(<<getOutput()); 72 | } 73 | 74 | /** 75 | * @testdox with --limit and --offset. 76 | */ 77 | public function testWithRange(): void { 78 | $process = Process::fromShellCommandline('drall site:directories --offset=2 --limit=2', static::PATH_DRUPAL); 79 | $process->run(); 80 | $this->assertOutputEquals(<<getOutput()); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /.docker/main/drupal/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A Drupal multi-site installation for developing and testing Drall.", 3 | "type": "project", 4 | "license": "GPL-2.0-or-later", 5 | "repositories": [ 6 | { 7 | "type": "composer", 8 | "url": "https://packages.drupal.org/8" 9 | }, 10 | { 11 | "type": "path", 12 | "url": "/opt/drall", 13 | "options": { 14 | "symlink": true 15 | } 16 | } 17 | ], 18 | "require": { 19 | "composer/installers": "^2", 20 | "drupal/core-composer-scaffold": "*", 21 | "drupal/core-recommended": "^11", 22 | "drupal/core-vendor-hardening": "*", 23 | "jigarius/drall": "*" 24 | }, 25 | "conflict": { 26 | "drupal/drupal": "*" 27 | }, 28 | "minimum-stability": "dev", 29 | "prefer-stable": true, 30 | "config": { 31 | "sort-packages": true, 32 | "allow-plugins": { 33 | "composer/installers": true, 34 | "dealerdirect/phpcodesniffer-composer-installer": true, 35 | "drupal/core-composer-scaffold": true, 36 | "drupal/core-project-message": true, 37 | "drupal/core-vendor-hardening": true, 38 | "phpro/grumphp": true 39 | } 40 | }, 41 | "extra": { 42 | "drupal-scaffold": { 43 | "locations": { 44 | "web-root": "web/" 45 | } 46 | }, 47 | "installer-paths": { 48 | "web/core": [ 49 | "type:drupal-core" 50 | ], 51 | "web/libraries/{$name}": [ 52 | "type:drupal-library" 53 | ], 54 | "web/modules/contrib/{$name}": [ 55 | "type:drupal-module" 56 | ], 57 | "web/profiles/contrib/{$name}": [ 58 | "type:drupal-profile" 59 | ], 60 | "web/themes/contrib/{$name}": [ 61 | "type:drupal-theme" 62 | ], 63 | "drush/Commands/contrib/{$name}": [ 64 | "type:drupal-drush" 65 | ], 66 | "web/modules/custom/{$name}": [ 67 | "type:drupal-custom-module" 68 | ], 69 | "web/profiles/custom/{$name}": [ 70 | "type:drupal-custom-profile" 71 | ], 72 | "web/themes/custom/{$name}": [ 73 | "type:drupal-custom-theme" 74 | ] 75 | } 76 | }, 77 | "require-dev": { 78 | "phpro/grumphp": "^2" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /test/Integration/Command/SiteAliasesCommandTest.php: -------------------------------------------------------------------------------- 1 | run(); 20 | $this->assertStringContainsString('Package "drupal/core" is not installed', $process->getErrorOutput()); 21 | } 22 | 23 | /** 24 | * @testdox with an empty Drupal installation. 25 | */ 26 | public function testWithEmptyDrupal(): void { 27 | $process = Process::fromShellCommandline('drall site:aliases', static::PATH_EMPTY_DRUPAL); 28 | $process->run(); 29 | $this->assertStringContainsString('[warning] No site aliases found.', $process->getOutput()); 30 | } 31 | 32 | /** 33 | * @testdox with a valid Drupal installation. 34 | */ 35 | public function testExecute(): void { 36 | $process = Process::fromShellCommandline('drall site:aliases', static::PATH_DRUPAL); 37 | $process->run(); 38 | $this->assertOutputEquals(<<getOutput()); 46 | } 47 | 48 | /** 49 | * @testdox with --filter. 50 | */ 51 | public function testWithFilter(): void { 52 | $process = Process::fromShellCommandline( 53 | 'drall site:aliases --filter="leo||ralph"', 54 | static::PATH_DRUPAL, 55 | ); 56 | $process->run(); 57 | $this->assertOutputEquals(<<getOutput()); 62 | } 63 | 64 | /** 65 | * @testdox with --group. 66 | */ 67 | public function testWithGroup(): void { 68 | $process = Process::fromShellCommandline( 69 | 'drall site:aliases --group=reddish', 70 | static::PATH_DRUPAL 71 | ); 72 | $process->run(); 73 | $this->assertOutputEquals(<<getOutput()); 78 | } 79 | 80 | /** 81 | * @testdox with --limit and --offset. 82 | */ 83 | public function testWithRange(): void { 84 | $process = Process::fromShellCommandline('drall site:aliases --offset=2 --limit=2', static::PATH_DRUPAL); 85 | $process->run(); 86 | $this->assertOutputEquals(<<getOutput()); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/TestCase.php: -------------------------------------------------------------------------------- 1 | createTempFilePath(); 60 | file_put_contents($path, $data); 61 | return $path; 62 | } 63 | 64 | protected function createDrupalFinderStub(?string $root = NULL): DrupalFinderComposerRuntime { 65 | $root ??= static::PATH_DRUPAL; 66 | $drupalFinder = $this->createStub(DrupalFinderComposerRuntime::class); 67 | $drupalFinder->method('getComposerRoot')->willReturn($root); 68 | $drupalFinder->method('getDrupalRoot')->willReturn("$root/web"); 69 | $drupalFinder->method('getVendorDir')->willReturn("$root/vendor"); 70 | return $drupalFinder; 71 | } 72 | 73 | protected function assertOutputEquals(string $expected, mixed $actual, string $message = ''): void { 74 | $this->assertEquals($expected, self::normalizeString($actual ?? ''), $message); 75 | } 76 | 77 | protected function assertOutputStartsWith(string $expected, mixed $actual, string $message = ''): void { 78 | $this->assertStringStartsWith($expected, self::normalizeString($actual ?? ''), $message); 79 | } 80 | 81 | protected function assertOutputContainsString(string $expected, mixed $actual, string $message = ''): void { 82 | $this->assertStringContainsString($expected, self::normalizeString($actual ?? ''), $message); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /test/Integration/Command/BaseCommandTest.php: -------------------------------------------------------------------------------- 1 | run(); 23 | $this->assertOutputStartsWith(<<getOutput()); 26 | 27 | // Short form. 28 | $process1 = Process::fromShellCommandline( 29 | 'drall exec -g bluish --dry-run -vv -- ./vendor/bin/drush st', 30 | static::PATH_DRUPAL, 31 | ); 32 | $process1->run(); 33 | $this->assertOutputStartsWith(<<getOutput()); 36 | } 37 | 38 | /** 39 | * @testdox Detects --filter. 40 | */ 41 | public function testWithFilter(): void { 42 | $process1 = Process::fromShellCommandline( 43 | 'drall exec --filter=leo --dry-run -vv -- ./vendor/bin/drush st', 44 | static::PATH_DRUPAL, 45 | ); 46 | $process1->run(); 47 | $this->assertOutputStartsWith(<<getOutput()); 50 | 51 | // Short form. 52 | $process2 = Process::fromShellCommandline( 53 | 'drall exec -f leo --dry-run -vv -- ./vendor/bin/drush st', 54 | static::PATH_DRUPAL, 55 | ); 56 | $process2->run(); 57 | $this->assertOutputStartsWith(<<getOutput()); 60 | } 61 | 62 | /** 63 | * @testdox Detects --offset and --limit. 64 | */ 65 | public function testWithRange(): void { 66 | $process1 = Process::fromShellCommandline( 67 | 'drall exec --offset=2 --dry-run -vv -- ./vendor/bin/drush st', 68 | static::PATH_DRUPAL, 69 | ); 70 | $process1->run(); 71 | $this->assertOutputStartsWith(<<getOutput()); 74 | 75 | $process2 = Process::fromShellCommandline( 76 | 'drall exec --limit=2 --dry-run -vv -- ./vendor/bin/drush st', 77 | static::PATH_DRUPAL, 78 | ); 79 | $process2->run(); 80 | $this->assertOutputStartsWith(<<getOutput()); 83 | 84 | $process3 = Process::fromShellCommandline( 85 | 'drall exec --offset=2 --limit=2 --dry-run -vv -- ./vendor/bin/drush st', 86 | static::PATH_DRUPAL, 87 | ); 88 | $process3->run(); 89 | $this->assertOutputStartsWith(<<getOutput()); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /test/Integration/Command/SiteKeysCommandTest.php: -------------------------------------------------------------------------------- 1 | run(); 20 | $this->assertStringContainsString('Package "drupal/core" is not installed', $process->getErrorOutput()); 21 | } 22 | 23 | /** 24 | * @testdox with an empty Drupal installation. 25 | */ 26 | public function testWithEmptyDrupal(): void { 27 | $process = Process::fromShellCommandline('drall site:keys', static::PATH_EMPTY_DRUPAL); 28 | $process->run(); 29 | $this->assertStringContainsString('[warning] No Drupal sites found.', $process->getOutput()); 30 | } 31 | 32 | /** 33 | * @testdox with a Drupal installation. 34 | */ 35 | public function testExecute(): void { 36 | $process = Process::fromShellCommandline('drall site:keys', static::PATH_DRUPAL); 37 | $process->run(); 38 | $this->assertOutputEquals(<<getOutput()); 53 | } 54 | 55 | /** 56 | * @testdox with --filter. 57 | */ 58 | public function testWithFilter(): void { 59 | $process = Process::fromShellCommandline('drall site:keys --filter="value~=@.local\$@"', static::PATH_DRUPAL); 60 | $process->run(); 61 | $this->assertOutputEquals(<<getOutput()); 69 | } 70 | 71 | /** 72 | * @testdox with --group. 73 | */ 74 | public function testWithGroup(): void { 75 | $process = Process::fromShellCommandline('drall site:keys --group=bluish', static::PATH_DRUPAL); 76 | $process->run(); 77 | $this->assertOutputEquals(<<getOutput()); 85 | } 86 | 87 | /** 88 | * @testdox with --limit and --offset. 89 | */ 90 | public function testWithRange(): void { 91 | $process = Process::fromShellCommandline('drall site:keys --offset=1 --limit=1', static::PATH_DRUPAL); 92 | $process->run(); 93 | $this->assertOutputEquals(<<getOutput()); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /.docker/main/drupal/web/sites/sites.php: -------------------------------------------------------------------------------- 1 | ..' => 'directory'. As an 26 | * example, to map https://www.drupal.org:8080/mysite/test to the configuration 27 | * directory sites/example.com, the array should be defined as: 28 | * @code 29 | * $sites = [ 30 | * '8080.www.drupal.org.mysite.test' => 'example.com', 31 | * ]; 32 | * @endcode 33 | * The URL, https://www.drupal.org:8080/mysite/test/, could be a symbolic link 34 | * or an Apache Alias directive that points to the Drupal root containing 35 | * index.php. An alias could also be created for a subdomain. See the 36 | * @link https://www.drupal.org/documentation/install online Drupal installation guide @endlink 37 | * for more information on setting up domains, subdomains, and subdirectories. 38 | * 39 | * The following examples look for a site configuration in sites/example.com: 40 | * @code 41 | * URL: http://dev.drupal.org 42 | * $sites['dev.drupal.org'] = 'example.com'; 43 | * 44 | * URL: http://localhost/example 45 | * $sites['localhost.example'] = 'example.com'; 46 | * 47 | * URL: http://localhost:8080/example 48 | * $sites['8080.localhost.example'] = 'example.com'; 49 | * 50 | * URL: https://www.drupal.org:8080/mysite/test/ 51 | * $sites['8080.www.drupal.org.mysite.test'] = 'example.com'; 52 | * @endcode 53 | * 54 | * @see default.settings.php 55 | * @see \Drupal\Core\DrupalKernel::getSitePath() 56 | * @see https://www.drupal.org/documentation/install/multi-site 57 | */ 58 | 59 | $sites['tmnt.com'] = 'default'; 60 | $sites['cowabunga.com'] = 'default'; 61 | $sites['tmnt.drall.local'] = 'default'; 62 | 63 | $sites['donatello.com'] = 'donnie'; 64 | $sites['8080.donatello.com'] = 'donnie'; 65 | $sites['donnie.drall.local'] = 'donnie'; 66 | 67 | $sites['leonardo.com'] = 'leo'; 68 | $sites['leo.drall.local'] = 'leo'; 69 | 70 | $sites['michelangelo.com'] = 'mikey'; 71 | $sites['mikey.drall.local'] = 'mikey'; 72 | 73 | $sites['raphael.com'] = 'ralph'; 74 | $sites['ralph.drall.local'] = 'ralph'; 75 | -------------------------------------------------------------------------------- /src/Model/SiteDetectorOptions.php: -------------------------------------------------------------------------------- 1 | setGroup($group); 24 | } 25 | 26 | if (isset($options['filter'])) { 27 | $result->setFilter($options['filter']); 28 | } 29 | 30 | if (isset($options['offset'])) { 31 | if (!is_numeric($options['offset'])) { 32 | throw new \InvalidArgumentException('Offset must be an integer.'); 33 | } 34 | 35 | $result->setOffset($options['offset']); 36 | } 37 | 38 | if (isset($options['limit'])) { 39 | if (!is_numeric($options['limit'])) { 40 | throw new \InvalidArgumentException('Limit must be an integer.'); 41 | } 42 | 43 | $result->setLimit($options['limit']); 44 | } 45 | 46 | return $result; 47 | } 48 | 49 | public static function fromInput(InputInterface $input): static { 50 | $aOptions = []; 51 | 52 | if ( 53 | $input->hasOption('group') && 54 | $group = $input->getOption('group') 55 | ) { 56 | $aOptions['group'] = $group; 57 | } 58 | 59 | if ( 60 | $input->hasOption('filter') && 61 | $filter = $input->getOption('filter') 62 | ) { 63 | $aOptions['filter'] = $filter; 64 | } 65 | 66 | if ( 67 | $input->hasOption('offset') && 68 | $offset = $input->getOption('offset') 69 | ) { 70 | $aOptions['offset'] = $offset; 71 | } 72 | 73 | if ( 74 | $input->hasOption('limit') && 75 | $limit = $input->getOption('limit') 76 | ) { 77 | $aOptions['limit'] = $limit; 78 | } 79 | 80 | return self::fromArray($aOptions); 81 | } 82 | 83 | public function getFilter(): ?string { 84 | return $this->filter; 85 | } 86 | 87 | public function setFilter(?string $filter): static { 88 | $this->filter = $filter; 89 | return $this; 90 | } 91 | 92 | public function getGroup(): ?string { 93 | return $this->group; 94 | } 95 | 96 | public function setGroup(?string $group): static { 97 | $this->group = $group; 98 | return $this; 99 | } 100 | 101 | public function getOffset(): ?int { 102 | return $this->offset; 103 | } 104 | 105 | public function setOffset(?int $offset): static { 106 | $this->offset = $offset; 107 | return $this; 108 | } 109 | 110 | public function getLimit(): ?int { 111 | return $this->limit; 112 | } 113 | 114 | public function setLimit(?int $limit): static { 115 | if ($limit < 1) { 116 | throw new \ValueError('Limit must be greater than zero.'); 117 | } 118 | 119 | $this->limit = $limit; 120 | return $this; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/Drall.php: -------------------------------------------------------------------------------- 1 | setName(self::NAME); 32 | $this->setVersion(InstalledVersions::getPrettyVersion('jigarius/drall') ?? 'unknown'); 33 | $this->setAutoExit(FALSE); 34 | 35 | $this->add(new SiteDirectoriesCommand()); 36 | $this->add(new SiteKeysCommand()); 37 | $this->add(new SiteAliasesCommand()); 38 | $this->add(new ExecCommand()); 39 | } 40 | 41 | protected function configureIO(InputInterface $input, OutputInterface $output): void { 42 | parent::configureIO($input, $output); 43 | 44 | if ( 45 | $input->hasParameterOption('--debug', TRUE) || 46 | $input->hasParameterOption('-d', TRUE) 47 | ) { 48 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); 49 | } 50 | 51 | // The parent::configureIO sets verbosity in a SHELL_VERBOSITY. This causes 52 | // other Symfony Console apps to become verbose, for example, Drush. To 53 | // prevent such behavior, we force the SHELL_VERBOSITY to be normal. 54 | $shellVerbosity = 0; 55 | if (\function_exists('putenv')) { 56 | @putenv("SHELL_VERBOSITY=$shellVerbosity"); 57 | } 58 | $_ENV['SHELL_VERBOSITY'] = $shellVerbosity; 59 | $_SERVER['SHELL_VERBOSITY'] = $shellVerbosity; 60 | } 61 | 62 | protected function getDefaultInputDefinition(): InputDefinition { 63 | $definition = parent::getDefaultInputDefinition(); 64 | 65 | // Remove unneeded options. 66 | $options = $definition->getOptions(); 67 | unset( 68 | $options['no-interaction'], 69 | $options['silent'], 70 | ); 71 | $definition->setOptions($options); 72 | 73 | $definition->addOption(new InputOption( 74 | 'debug', 75 | 'd', 76 | InputOption::VALUE_NONE, 77 | 'Display debugging output for Drall.' 78 | )); 79 | 80 | return $definition; 81 | } 82 | 83 | public function find(string $name): Command { 84 | try { 85 | return parent::find($name); 86 | } 87 | catch (CommandNotFoundException) { 88 | throw new CommandNotFoundException(<<assertSame(Drall::NAME, $app->getName()); 18 | } 19 | 20 | /** 21 | * @testdox Default input options are defined. 22 | */ 23 | public function testDefaultInputOptions() { 24 | $app = new Drall(); 25 | $options = $app->getDefinition()->getOptions(); 26 | 27 | $this->assertEquals([ 28 | 'help', 29 | 'quiet', 30 | 'verbose', 31 | 'version', 32 | 'ansi', 33 | 'debug', 34 | ], array_keys($options)); 35 | } 36 | 37 | /** 38 | * @testdox Verbosity quiet. 39 | */ 40 | public function testVerbosityQuiet() { 41 | $tester = new ApplicationTester(new Drall()); 42 | 43 | $tester->run(['command' => 'version', '--quiet' => TRUE]); 44 | $this->assertEquals(OutputInterface::VERBOSITY_QUIET, $tester->getOutput()->getVerbosity()); 45 | 46 | $tester->run(['command' => 'version', '-q' => TRUE]); 47 | $this->assertEquals(OutputInterface::VERBOSITY_QUIET, $tester->getOutput()->getVerbosity()); 48 | } 49 | 50 | /** 51 | * @testdox Verbosity level 0. 52 | */ 53 | public function testVerbosityNormal() { 54 | $tester = new ApplicationTester(new Drall()); 55 | $tester->run(['command' => 'version']); 56 | $this->assertEquals(OutputInterface::VERBOSITY_NORMAL, $tester->getOutput()->getVerbosity()); 57 | } 58 | 59 | /** 60 | * @testdox Verbosity level 1. 61 | */ 62 | public function testVerbosityVerbose() { 63 | $tester = new ApplicationTester(new Drall()); 64 | 65 | $tester->run(['command' => 'version', '--verbose' => TRUE]); 66 | $this->assertEquals(OutputInterface::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity()); 67 | 68 | $tester->run(['command' => 'version', '-v' => TRUE]); 69 | $this->assertEquals(OutputInterface::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity()); 70 | } 71 | 72 | /** 73 | * @testdox Verbosity level 2. 74 | */ 75 | public function testVerbosityVeryVerbose() { 76 | $tester = new ApplicationTester(new Drall()); 77 | 78 | $tester->run(['command' => 'version', '--verbose' => 2]); 79 | $this->assertEquals(OutputInterface::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity()); 80 | 81 | $tester->run(['command' => 'version', '-vv' => TRUE]); 82 | $this->assertEquals(OutputInterface::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity()); 83 | } 84 | 85 | /** 86 | * @testdox Verbosity level 3. 87 | */ 88 | public function testVerbosityDebug() { 89 | $tester = new ApplicationTester(new Drall()); 90 | 91 | $tester->run(['command' => 'version', '--verbose' => 3]); 92 | $this->assertEquals(OutputInterface::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity()); 93 | 94 | $tester->run(['command' => 'version', '-vvv' => TRUE]); 95 | $this->assertEquals(OutputInterface::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity()); 96 | 97 | $tester->run(['command' => 'version', '-d']); 98 | $this->assertEquals(OutputInterface::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity()); 99 | 100 | $tester->run(['command' => 'version', '--debug' => TRUE]); 101 | $this->assertEquals(OutputInterface::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity()); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: ssh 2 | ssh: 3 | docker compose exec main bash 4 | 5 | 6 | .PHONY: provision 7 | provision: provision/env provision/drall provision/no-drupal provision/empty-drupal provision/drupal 8 | 9 | 10 | .PHONY: provision/env 11 | provision/env: 12 | cp /opt/drall/bin/drall-launcher /usr/local/bin/drall 13 | cp /opt/drall/bin/drush-launcher /usr/local/bin/drush 14 | 15 | 16 | .PHONY: provision/drupal 17 | provision/drupal: 18 | mkdir -p /opt/drupal 19 | 20 | cp /opt/drall/.docker/main/drupal/composer.json /opt/drupal/ || echo "Skipping: drupal/composer.json" 21 | rm -f /opt/drupal/composer.lock 22 | composer --working-dir=/opt/drupal install --no-progress 23 | cp -r /opt/drall/.docker/main/drupal/drush /opt/drupal/ || echo "Skipping: drupal/drush" 24 | cp -r /opt/drall/.docker/main/drupal/web/sites /opt/drupal/web/ || echo "Skipping: drupal/web/sites" 25 | 26 | mkdir -p /opt/drupal/web/sites/default 27 | mkdir -p /opt/drupal/web/sites/donnie 28 | mkdir -p /opt/drupal/web/sites/leo 29 | mkdir -p /opt/drupal/web/sites/mikey 30 | mkdir -p /opt/drupal/web/sites/ralph 31 | 32 | cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/default/settings.php 33 | cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/donnie/settings.php 34 | cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/leo/settings.php 35 | cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/mikey/settings.php 36 | cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/ralph/settings.php 37 | 38 | @echo '' 39 | @echo 'Drupal databases can be provisioned with: make provision/drupal/database' 40 | 41 | 42 | .PHONY: provision/no-drupal 43 | provision/no-drupal: 44 | mkdir -p /opt/no-drupal 45 | cp /opt/drall/.docker/main/no-drupal/composer.json /opt/no-drupal/ || echo "Skipping: no-drupal/composer.json" 46 | rm -f /opt/no-drupal/composer.lock 47 | composer --working-dir=/opt/no-drupal install --no-progress 48 | 49 | 50 | .PHONY: provision/empty-drupal 51 | provision/empty-drupal: 52 | mkdir -p /opt/empty-drupal 53 | cp /opt/drall/.docker/main/empty-drupal/composer.json /opt/empty-drupal/ || echo "Skipping: empty-drupal/composer.json" 54 | rm -f /opt/empty-drupal/composer.lock 55 | composer --working-dir=/opt/empty-drupal install --no-progress 56 | cp /opt/drall/.docker/main/empty-drupal/web/sites/sites.php /opt/empty-drupal/web/sites/sites.php 57 | 58 | 59 | .PHONY: provision/drupal/database 60 | provision/drupal/database: 61 | rm -f web/sites/*/settings.php 62 | 63 | ./vendor/bin/drush site:install -y minimal --db-url="mysql://drupal:drupal@database:3306/tmnt" --uri=default --account-name=tmnt-root --account-mail=tmnt@localhost --account-pass=cowabunga --site-name=TMNT 64 | chown -R www-data:www-data web/sites/default 65 | 66 | ./vendor/bin/drush site:install -y minimal --sites-subdir=donnie --db-url="mysql://drupal:drupal@database:3306/donnie" --uri=donnie --account-name=tmnt-root --account-mail=tmnt@localhost --account-pass=cowabunga --site-name=Donatello 67 | chown -R www-data:www-data web/sites/donnie 68 | 69 | ./vendor/bin/drush site:install -y minimal --sites-subdir=leo --db-url="mysql://drupal:drupal@database:3306/leo" --uri=leo --account-name=tmnt-root --account-mail=tmnt@localhost --account-pass=cowabunga --site-name=Leonardo 70 | chown -R www-data:www-data web/sites/leo 71 | 72 | ./vendor/bin/drush site:install -y minimal --sites-subdir=mikey --db-url="mysql://drupal:drupal@database:3306/mikey" --uri=mikey --account-name=tmnt-root --account-mail=tmnt@localhost --account-pass=cowabunga --site-name=Michaelangelo 73 | chown -R www-data:www-data web/sites/mikey 74 | 75 | ./vendor/bin/drush site:install -y minimal --sites-subdir=ralph --db-url="mysql://drupal:drupal@database:3306/ralph" --uri=ralph --account-name=tmnt-root --account-mail=tmnt@localhost --account-pass=cowabunga --site-name=Raphael 76 | chown -R www-data:www-data web/sites/ralph 77 | 78 | 79 | .PHONY: provision/drall 80 | provision/drall: 81 | composer install --working-dir=/opt/drall --no-progress 82 | 83 | 84 | .PHONY: coverage-report/text 85 | coverage-report/text: 86 | cat /opt/drall/.coverage/text 87 | 88 | 89 | .PHONY: coverage-report/html 90 | coverage-report/html: 91 | open .coverage/html/dashboard.html 92 | 93 | 94 | .PHONY: lint 95 | lint: 96 | composer --working-dir=/opt/drall run lint 97 | 98 | 99 | .PHONY: test 100 | test: 101 | XDEBUG_MODE=coverage composer --working-dir=/opt/drall run test 102 | 103 | 104 | .PHONY: info 105 | info: 106 | @echo "Path: $(PATH)" 107 | @echo "PWD: $(PWD)" 108 | @echo "Drupal path: $(DRUPAL_PATH)" 109 | @composer --version 110 | which drall 111 | -------------------------------------------------------------------------------- /src/Service/SiteDetector.php: -------------------------------------------------------------------------------- 1 | setDrupalFinder($drupalFinder); 29 | 30 | if (!$siteAliasManager) { 31 | $siteAliasManager = new SiteAliasManager(new SiteAliasFileLoader()); 32 | $siteAliasManager->addSearchLocation($drupalFinder->getComposerRoot() . '/drush/sites'); 33 | } 34 | $this->setSiteAliasManager($siteAliasManager); 35 | } 36 | 37 | /** 38 | * Get a list of site directory names for a site group. 39 | * 40 | * @param \Drall\Model\SiteDetectorOptions|null $options 41 | * Options. 42 | * 43 | * @return array 44 | * Site directory names. 45 | */ 46 | public function getSiteDirNames(?SiteDetectorOptions $options = NULL): array { 47 | $options = $options ?? new SiteDetectorOptions(); 48 | 49 | if (!$sitesFile = $this->getSitesFile($options->getGroup())) { 50 | return []; 51 | } 52 | 53 | $result = $sitesFile->getDirNames(); 54 | $result = $this->applyFilter($result, $options->getFilter() ?? ''); 55 | return $this->applyRange($result, $options->getOffset(), $options->getLimit()); 56 | } 57 | 58 | /** 59 | * Get a list of site URIs. 60 | * 61 | * @param \Drall\Model\SiteDetectorOptions|null $options 62 | * Options. 63 | * @param bool $unique 64 | * Whether to return unique keys only. 65 | * 66 | * @return array 67 | * Keys from the $sites array. 68 | */ 69 | public function getSiteKeys(?SiteDetectorOptions $options = NULL, bool $unique = FALSE): array { 70 | $options = $options ?? new SiteDetectorOptions(); 71 | if (!$sitesFile = $this->getSitesFile($options->getGroup())) { 72 | return []; 73 | } 74 | 75 | $result = $sitesFile->getKeys($unique); 76 | $result = $this->applyFilter($result, $options->getFilter() ?? ''); 77 | return $this->applyRange($result, $options->getOffset(), $options->getLimit()); 78 | } 79 | 80 | /** 81 | * Get site aliases. 82 | * 83 | * @param \Drall\Model\SiteDetectorOptions|null $options 84 | * Options. 85 | * 86 | * @return string[] 87 | * Site aliases. 88 | */ 89 | public function getSiteAliases(?SiteDetectorOptions $options = NULL): array { 90 | $options = $options ?? new SiteDetectorOptions(); 91 | // Use Drupal Finder to ensure that the Drupal is installed. This ensures 92 | // consistency in errors raised by methods that depend on sites.*.php. 93 | $this->drupalFinder()->getDrupalRoot(); 94 | 95 | $result = array_values($this->siteAliasManager()->getMultiple()); 96 | 97 | if ($group = $options->getGroup()) { 98 | $result = array_filter($result, function ($alias) use ($group) { 99 | return in_array($group, $alias->get('drall.groups') ?? []); 100 | }); 101 | } 102 | 103 | $result = array_map(fn($a) => $a->name(), $result); 104 | $result = $this->applyFilter($result, $options->getFilter() ?? ''); 105 | return $this->applyRange($result, $options->getOffset(), $options->getLimit()); 106 | } 107 | 108 | /** 109 | * Get site names derived from aliases. 110 | * 111 | * If there are aliases like @foo.dev and @foo.prod, then @foo part is 112 | * considered the site name. 113 | * 114 | * @param \Drall\Model\SiteDetectorOptions|null $options 115 | * Options. 116 | * 117 | * @return array 118 | * An array of site alias names with the @ prefix. 119 | */ 120 | public function getSiteAliasNames(?SiteDetectorOptions $options = NULL): array { 121 | $options = $options ?? new SiteDetectorOptions(); 122 | 123 | // Certain options must be used only once in this method. 124 | // Thus, we do not forward them to ::getSiteAliases(). 125 | $saOptions = new SiteDetectorOptions(); 126 | $saOptions->setGroup($options->getGroup()); 127 | 128 | $result = array_map(function ($siteAlias) { 129 | return explode('.', $siteAlias)[0]; 130 | }, $this->getSiteAliases($saOptions)); 131 | 132 | $result = array_unique(array_values($result)); 133 | $result = $this->applyFilter($result, $options->getFilter() ?? ''); 134 | return $this->applyRange($result, $options->getOffset(), $options->getLimit()); 135 | } 136 | 137 | /** 138 | * Gets the path to the applicable drush binary. 139 | * 140 | * @return string 141 | * Path/to/drush. 142 | */ 143 | public function getDrushPath(): string { 144 | return $this->drupalFinder->getVendorDir() . "/bin/drush"; 145 | } 146 | 147 | private function getSitesFile($group = NULL): ?SitesFile { 148 | if (!$drupalRoot = $this->drupalFinder->getDrupalRoot()) { 149 | return NULL; 150 | } 151 | 152 | $basename = 'sites.php'; 153 | if ($group) { 154 | $basename = "sites.$group.php"; 155 | } 156 | 157 | return new SitesFile("$drupalRoot/sites/$basename"); 158 | } 159 | 160 | /** 161 | * Filter data by expressions. 162 | * 163 | * @param array $data 164 | * The data. 165 | * @param string $expression 166 | * A filter expression. 167 | * @param string $default_filter_field 168 | * The default field by which to filter. 169 | * 170 | * @return array 171 | * Filtered data. 172 | * 173 | * @see https://packagist.org/packages/consolidation/filter-via-dot-access-data 174 | */ 175 | private function applyFilter( 176 | array $data, 177 | string $expression, 178 | string $default_filter_field = 'value', 179 | ): array { 180 | if (empty($data) || empty($expression)) { 181 | return $data; 182 | } 183 | 184 | if ($is_flat = !is_array(reset($data))) { 185 | $data = array_map(fn($r) => [$default_filter_field => $r], $data); 186 | } 187 | 188 | $factory = LogicalOpFactory::get(); 189 | $op = $factory->evaluate($expression, $default_filter_field); 190 | $expression = new FilterOutputData(); 191 | 192 | $result = $expression->filter($data, $op); 193 | 194 | if ($is_flat) { 195 | $result = array_column($result, $default_filter_field); 196 | } 197 | 198 | return $result; 199 | } 200 | 201 | /** 202 | * Get data after applying the given offset and limit. 203 | * 204 | * @param array $data 205 | * The data. 206 | * @param int|null $offset 207 | * An offset. 208 | * @param int|null $limit 209 | * A limit. 210 | * 211 | * @return array 212 | * The data after applying the range. 213 | */ 214 | private function applyRange(array $data, ?int $offset, ?int $limit): array { 215 | if (is_null($offset) && is_null($limit)) { 216 | return $data; 217 | } 218 | 219 | return array_splice($data, $offset ?? 0, $limit); 220 | } 221 | 222 | /** 223 | * Detects sites in a "sites" directory. 224 | * 225 | * Builds a $sites array based on the contents of a given "sites" directory. 226 | * The detection is based on the presence of settings.php. 227 | * 228 | * @param string $path 229 | * Path to a DRUPAL/sites directory. 230 | * 231 | * @return array 232 | * An associative array for use as $sites. 233 | */ 234 | public static function detectFromDirectory(string $path): array { 235 | $pattern = implode(DIRECTORY_SEPARATOR, [$path, '*', 'settings.php']); 236 | 237 | $result = []; 238 | foreach (glob($pattern) as $item) { 239 | if (!is_file($item)) { 240 | continue; 241 | } 242 | 243 | $dirname = basename(dirname($item)); 244 | $result[$dirname] = $dirname; 245 | } 246 | 247 | return $result; 248 | } 249 | 250 | } 251 | -------------------------------------------------------------------------------- /test/Unit/Service/SiteDetectorTest.php: -------------------------------------------------------------------------------- 1 | addLoader('yml', new YamlDataFileLoader()); 23 | $siteAliasManager = new SiteAliasManager($siteAliasFileLoader, static::PATH_DRUPAL); 24 | $siteAliasManager->addSearchLocation('drush/sites'); 25 | 26 | $this->subject = new SiteDetector($this->createDrupalFinderStub(), $siteAliasManager); 27 | } 28 | 29 | public function testGetSiteDirNames() { 30 | $this->assertEquals( 31 | ['default', 'donnie', 'leo', 'mikey', 'ralph'], 32 | $this->subject->getSiteDirNames() 33 | ); 34 | } 35 | 36 | public function testGetSiteDirNamesWithGroup() { 37 | $options = new SiteDetectorOptions(); 38 | $options->setGroup('bluish'); 39 | $this->assertEquals( 40 | ['donnie', 'leo'], 41 | $this->subject->getSiteDirNames($options), 42 | ); 43 | } 44 | 45 | public function testGetSiteDirNamesWithFilter() { 46 | $options = new SiteDetectorOptions(); 47 | $options->setFilter('leo||ralph'); 48 | $this->assertEquals( 49 | ['leo', 'ralph'], 50 | $this->subject->getSiteDirNames($options) 51 | ); 52 | } 53 | 54 | public function testGetSiteDirNamesWithRange() { 55 | $options = new SiteDetectorOptions(); 56 | $options->setOffset(2)->setLimit(2); 57 | $this->assertEquals( 58 | ['leo', 'mikey'], 59 | $this->subject->getSiteDirNames($options), 60 | ); 61 | } 62 | 63 | public function testGetSiteDirNamesWithNoDrupal() { 64 | $subject = new SiteDetector( 65 | $this->createDrupalFinderStub(static::PATH_NO_DRUPAL), 66 | ); 67 | $this->expectException(\RuntimeException::class); 68 | $subject->getSiteDirNames(); 69 | } 70 | 71 | public function testGetSiteDirNamesWithEmptyDrupal() { 72 | $subject = new SiteDetector( 73 | $this->createDrupalFinderStub(static::PATH_EMPTY_DRUPAL), 74 | ); 75 | $this->assertEquals([], $subject->getSiteDirNames()); 76 | } 77 | 78 | public function testGetSiteKeys() { 79 | $this->assertEquals( 80 | [ 81 | 'tmnt.com', 82 | 'cowabunga.com', 83 | 'tmnt.drall.local', 84 | 'donatello.com', 85 | '8080.donatello.com', 86 | 'donnie.drall.local', 87 | 'leonardo.com', 88 | 'leo.drall.local', 89 | 'michelangelo.com', 90 | 'mikey.drall.local', 91 | 'raphael.com', 92 | 'ralph.drall.local', 93 | ], 94 | $this->subject->getSiteKeys() 95 | ); 96 | 97 | $options = new SiteDetectorOptions(); 98 | $options->setGroup('reddish'); 99 | $this->assertEquals( 100 | [ 101 | 'michelangelo.com', 102 | 'mikey.drall.local', 103 | 'raphael.com', 104 | 'ralph.drall.local', 105 | ], 106 | $this->subject->getSiteKeys($options) 107 | ); 108 | } 109 | 110 | public function testGetSiteKeysWithGroup() { 111 | $options = new SiteDetectorOptions(); 112 | $options->setGroup('bluish'); 113 | $this->assertEquals( 114 | [ 115 | 'donatello.com', 116 | '8080.donatello.com', 117 | 'donnie.drall.local', 118 | 'leonardo.com', 119 | 'leo.drall.local', 120 | ], 121 | $this->subject->getSiteKeys($options) 122 | ); 123 | } 124 | 125 | public function testGetSiteKeysWithFilter() { 126 | $options = new SiteDetectorOptions(); 127 | $options->setFilter('cowabunga'); 128 | $this->assertEquals( 129 | ['cowabunga.com'], 130 | $this->subject->getSiteKeys($options) 131 | ); 132 | } 133 | 134 | public function testGetSiteKeysWithRange() { 135 | $options = new SiteDetectorOptions(); 136 | $options->setOffset(2)->setLimit(1); 137 | $this->assertEquals( 138 | ['tmnt.drall.local'], 139 | $this->subject->getSiteKeys($options) 140 | ); 141 | } 142 | 143 | public function testGetUniqueSiteKeys() { 144 | $options = new SiteDetectorOptions(); 145 | $this->assertEquals( 146 | [ 147 | 'tmnt.drall.local', 148 | 'donnie.drall.local', 149 | 'leo.drall.local', 150 | 'mikey.drall.local', 151 | 'ralph.drall.local', 152 | ], 153 | $this->subject->getSiteKeys($options, TRUE) 154 | ); 155 | } 156 | 157 | public function testGetUniqueSiteKeysWithFilter() { 158 | $options = new SiteDetectorOptions(); 159 | $options->setFilter('leo||ralph'); 160 | $this->assertEquals( 161 | ['leo.drall.local', 'ralph.drall.local'], 162 | $this->subject->getSiteKeys($options, TRUE) 163 | ); 164 | } 165 | 166 | public function testGetSiteKeysWithNoDrupal() { 167 | $subject = new SiteDetector( 168 | $this->createDrupalFinderStub(static::PATH_NO_DRUPAL), 169 | ); 170 | $this->expectException(\RuntimeException::class); 171 | $subject->getSiteKeys(); 172 | } 173 | 174 | public function testGetSiteKeysWithEmptyDrupal() { 175 | $subject = new SiteDetector( 176 | $this->createDrupalFinderStub(static::PATH_EMPTY_DRUPAL), 177 | ); 178 | $this->assertEquals([], $subject->getSiteKeys()); 179 | } 180 | 181 | public function testGetSiteAliases() { 182 | $this->assertEquals( 183 | [ 184 | '@donnie.local', 185 | '@leo.local', 186 | '@mikey.local', 187 | '@ralph.local', 188 | '@tmnt.local', 189 | ], 190 | $this->subject->getSiteAliases() 191 | ); 192 | } 193 | 194 | public function testGetSiteAliasesWithGroup() { 195 | $options = new SiteDetectorOptions(); 196 | $options->setGroup('bluish'); 197 | $this->assertEquals( 198 | ['@donnie.local', '@leo.local'], 199 | $this->subject->getSiteAliases($options) 200 | ); 201 | } 202 | 203 | public function getGetSiteAliasesWithFilter() { 204 | $this->assertEquals( 205 | ['@leo.local', '@ralph.local'], 206 | $this->subject->getSiteAliases(NULL, 'leo||ralph') 207 | ); 208 | } 209 | 210 | public function getGetSiteAliasesWithRange() { 211 | $options = new SiteDetectorOptions(); 212 | $options->setOffset(2)->setLimit(2); 213 | $this->assertEquals( 214 | ['@leo.local', '@ralph.local'], 215 | $this->subject->getSiteAliases($options), 216 | ); 217 | } 218 | 219 | public function testGetSiteAliasNames() { 220 | $this->assertEquals( 221 | ['@donnie', '@leo', '@mikey', '@ralph', '@tmnt'], 222 | $this->subject->getSiteAliasNames() 223 | ); 224 | } 225 | 226 | public function testGetSiteAliasNamesWithGroup() { 227 | $options = new SiteDetectorOptions(); 228 | $options->setGroup('bluish'); 229 | $this->assertEquals( 230 | ['@donnie', '@leo'], 231 | $this->subject->getSiteAliasNames($options) 232 | ); 233 | } 234 | 235 | public function testGetSiteAliasNamesWithFilter() { 236 | $options = new SiteDetectorOptions(); 237 | $options->setFilter('leo||ralph'); 238 | $this->assertEquals( 239 | ['@leo', '@ralph'], 240 | $this->subject->getSiteAliasNames($options) 241 | ); 242 | } 243 | 244 | public function testGetSiteAliasNamesWithRange() { 245 | $options = new SiteDetectorOptions(); 246 | $options->setOffset(2)->setLimit(2); 247 | $this->assertEquals( 248 | ['@mikey', '@ralph'], 249 | $this->subject->getSiteAliasNames($options) 250 | ); 251 | } 252 | 253 | public function testGetSiteAliasNamesWithNothingToFilter() { 254 | $options = new SiteDetectorOptions(); 255 | $options->setGroup('unknown') 256 | ->setFilter('leo||ralph'); 257 | $this->assertEquals( 258 | [], 259 | $this->subject->getSiteAliasNames($options) 260 | ); 261 | } 262 | 263 | public function testGetDrushPath() { 264 | $this->assertEquals( 265 | '/opt/drupal/vendor/bin/drush', 266 | $this->subject->getDrushPath() 267 | ); 268 | } 269 | 270 | public function testDetectFromDirectory(): void { 271 | $this->assertEquals([ 272 | 'default' => 'default', 273 | 'donnie' => 'donnie', 274 | 'leo' => 'leo', 275 | 'mikey' => 'mikey', 276 | 'ralph' => 'ralph', 277 | ], SiteDetector::detectFromDirectory(static::PATH_DRUPAL . '/web/sites')); 278 | } 279 | 280 | public function testDetectFromIncorrectDirectory(): void { 281 | $this->assertEquals([], SiteDetector::detectFromDirectory('/foo')); 282 | } 283 | 284 | } 285 | -------------------------------------------------------------------------------- /src/Command/ExecCommand.php: -------------------------------------------------------------------------------- 1 | setName('exec'); 49 | $this->setAliases(['ex']); 50 | $this->setDescription('Execute a command on multiple Drupal sites.'); 51 | $this->addUsage('drush core:status'); 52 | $this->addUsage('./vendor/bin/drush core:status'); 53 | $this->addUsage('--group=GROUP -- drush core:status'); 54 | $this->addUsage('--filter=FILTER -- drush core:status'); 55 | $this->addUsage('--offset=2 --limit=2 -- drush core:status'); 56 | $this->addUsage('--workers=4 -- drush cache:rebuild'); 57 | $this->addUsage('ls web/sites/@@dir/settings.php'); 58 | $this->addUsage('\'echo "Working on @@site" && drush @@site.local core:status\''); 59 | 60 | $this->addArgument( 61 | 'cmd', 62 | InputArgument::REQUIRED | InputArgument::IS_ARRAY, 63 | 'A shell command.' 64 | ); 65 | 66 | $this->addOption( 67 | 'workers', 68 | 'w', 69 | InputOption::VALUE_OPTIONAL, 70 | 'Number of commands to execute in parallel.', 71 | 1, 72 | ); 73 | 74 | $this->addOption( 75 | 'interval', 76 | NULL, 77 | InputOption::VALUE_OPTIONAL, 78 | 'Number of seconds to wait between commands.', 79 | 0, 80 | ); 81 | 82 | $this->addOption( 83 | 'dry-run', 84 | 'X', 85 | InputOption::VALUE_NONE, 86 | 'Do not execute commands, only display them.' 87 | ); 88 | 89 | $this->addOption( 90 | 'no-buffer', 91 | 'B', 92 | InputOption::VALUE_NONE, 93 | 'Do not buffer output.' 94 | ); 95 | 96 | $this->addOption( 97 | 'no-progress', 98 | 'P', 99 | InputOption::VALUE_NONE, 100 | 'Do not show a progress bar.' 101 | ); 102 | 103 | $this->ignoreValidationErrors(); 104 | } 105 | 106 | protected function initialize(InputInterface $input, OutputInterface $output): void { 107 | $this->checkObsoleteOptions($input, $output); 108 | $this->checkOptionsSeparator($input, $output); 109 | $this->checkIntervalOption($input, $output); 110 | $this->checkWorkersOption($input, $output); 111 | $this->checkInterOptionCompatibility($input, $output); 112 | 113 | parent::initialize($input, $output); 114 | } 115 | 116 | private function checkOptionsSeparator(InputInterface $input, OutputInterface $output): void { 117 | if (!method_exists($input, 'getRawTokens')) { 118 | return; 119 | } 120 | 121 | // If options are present, an options separator (--) is required. 122 | if (in_array('--', $input->getRawTokens(TRUE))) { 123 | return; 124 | } 125 | 126 | $output->writeln(<<Incorrect: drall exec --dry-run drush --field=site core:status 130 | Correct: drall exec --dry-run -- drush --field=site core:status 131 | 132 | Notice the `--` between `--dry-run` and the word `drush`. 133 | EOT); 134 | throw new \RuntimeException('Missing options separator'); 135 | } 136 | 137 | private function checkObsoleteOptions(InputInterface $input, OutputInterface $output): void { 138 | if (!method_exists($input, 'getRawTokens')) { 139 | return; 140 | } 141 | 142 | // If obsolete --drall-* options are present, then abort. 143 | foreach ($input->getRawTokens(TRUE) as $token) { 144 | if (str_starts_with($token, '--drall-')) { 145 | $output->writeln(<<--drall-* options have been renamed. 147 | See https://github.com/jigarius/drall/issues/99 148 | EOT); 149 | throw new \RuntimeException('Obsolete options detected'); 150 | } 151 | } 152 | } 153 | 154 | private function checkIntervalOption(InputInterface $input, OutputInterface $output): void { 155 | $interval = $input->getOption('interval'); 156 | 157 | if ($interval < 0) { 158 | $output->writeln(<<--interval must be a positive integer. 160 | EOT); 161 | throw new \RuntimeException('Invalid options detected'); 162 | } 163 | } 164 | 165 | private function checkWorkersOption(InputInterface $input, OutputInterface $output): void { 166 | $workers = $input->getOption('workers'); 167 | $limit = self::WORKER_LIMIT; 168 | 169 | if ($workers < 1 || $workers > $limit) { 170 | $output->writeln(<<--workers must be between 1 and $limit. 172 | EOT); 173 | throw new \RuntimeException('Invalid options detected'); 174 | } 175 | } 176 | 177 | private function checkInterOptionCompatibility(InputInterface $input, OutputInterface $output): void { 178 | if ( 179 | $input->getOption('workers') > 1 && 180 | $input->getOption('interval') > 0 181 | ) { 182 | $output->writeln(<<--interval and --workers cannot be used together. 184 | EOT); 185 | throw new \RuntimeException('Incompatible options detected'); 186 | } 187 | } 188 | 189 | protected function preExecute(InputInterface $input, OutputInterface $output): void { 190 | parent::preExecute($input, $output); 191 | 192 | $workers = $input->getOption('workers'); 193 | if ($workers > 1) { 194 | $this->logger->notice("Using {count} workers.", ['count' => $workers]); 195 | } 196 | 197 | if ($interval = $input->getOption('interval')) { 198 | $this->logger->notice("Using a $interval-second interval between commands.", ['interval' => $interval]); 199 | } 200 | 201 | if ($input->getOption('no-buffer')) { 202 | $this->logger->notice("Using no output buffering."); 203 | } 204 | } 205 | 206 | protected function execute(InputInterface $input, OutputInterface $output): int { 207 | /** @var \Symfony\Component\Console\Output\ConsoleOutput $output */ 208 | $this->preExecute($input, $output); 209 | 210 | if (!$command = $this->getCommand($input, $output)) { 211 | return 1; 212 | } 213 | 214 | if (!$placeholder = $this->getUniquePlaceholder($command)) { 215 | return 1; 216 | } 217 | 218 | // Get all possible values for the placeholder. 219 | $sdOptions = SiteDetectorOptions::fromInput($input); 220 | $values = match ($placeholder) { 221 | Placeholder::Directory => $this->siteDetector()->getSiteDirNames($sdOptions), 222 | Placeholder::Site => $this->siteDetector()->getSiteAliasNames($sdOptions), 223 | Placeholder::Key => $this->siteDetector()->getSiteKeys($sdOptions), 224 | Placeholder::UniqueKey => $this->siteDetector()->getSiteKeys($sdOptions, TRUE), 225 | default => throw new \RuntimeException('Unrecognized placeholder: ' . $placeholder->value), 226 | }; 227 | 228 | if (empty($values)) { 229 | $this->logger->warning('No Drupal sites found.'); 230 | return 0; 231 | } 232 | 233 | // Display commands without executing them. 234 | if ($input->getOption('dry-run')) { 235 | foreach ($values as $value) { 236 | $pCommand = Placeholder::replace([$placeholder->value => $value], $command); 237 | $output->writeln($pCommand); 238 | } 239 | 240 | return Command::SUCCESS; 241 | } 242 | 243 | $textSection = $output->section(); 244 | $progressBar = new ProgressBar( 245 | $input->getOption('no-progress') ? new NullOutput() : $output->section(), 246 | count($values) 247 | ); 248 | 249 | $exitCode = Command::SUCCESS; 250 | 251 | // Within the iteration, all output must go through the output sections. 252 | // This keeps the text at the top and the progress bar at the bottom. 253 | Pipeline::fromIterable($values) 254 | ->concurrent($input->getOption('workers')) 255 | ->unordered() 256 | ->forEach((function ($value) use ( 257 | $input, 258 | $output, 259 | $textSection, 260 | $command, 261 | $placeholder, 262 | $progressBar, 263 | &$exitCode, 264 | ) { 265 | if ($this->isStopping) { 266 | return; 267 | } 268 | 269 | $pCommand = Placeholder::replace([$placeholder->value => $value], $command); 270 | $process = Process::start("($pCommand) 2>&1"); 271 | 272 | // Send process output directly to the output stream. 273 | if ( 274 | $input->getOption('no-buffer') && 275 | is_a($output, StreamOutput::class) 276 | ) { 277 | $wStream = new WritableResourceStream($output->getStream()); 278 | ByteStream\pipe($process->getStdout(), $wStream); 279 | } 280 | // Buffer process output until it finishes. 281 | elseif ($pOutput = rtrim(ByteStream\buffer($process->getStdout()))) { 282 | // Always display command output, even in --quiet mode. 283 | $textSection->writeln($pOutput, OutputInterface::VERBOSITY_QUIET); 284 | } 285 | 286 | if (Command::SUCCESS === $process->join()) { 287 | $textSection->writeln("✔ $value: Done"); 288 | } 289 | else { 290 | $textSection->writeln("✖ $value: Failed"); 291 | $exitCode = Command::FAILURE; 292 | } 293 | 294 | $progressBar->advance(); 295 | 296 | // Wait between commands if --interval is specified. 297 | if ($interval = $input->getOption('interval')) { 298 | sleep($interval); 299 | } 300 | })); 301 | 302 | if ($this->isStopping) { 303 | $output->writeln(''); 304 | return self::INTERRUPTED; 305 | } 306 | 307 | $progressBar->finish(); 308 | 309 | return $exitCode; 310 | } 311 | 312 | /** 313 | * Extracts the command to be executed by Drall. 314 | * 315 | * All drall-specific components are removed from the command. 316 | * 317 | * @param \Symfony\Component\Console\Input\InputInterface $input 318 | * Console input. 319 | * @param \Symfony\Component\Console\Output\OutputInterface $output 320 | * Console output. 321 | * 322 | * @return string|null 323 | * The command without Drall elements. 324 | * 325 | * @example 326 | * Input: /path/to/drall exec --verbose -- drush st --fields=site 327 | * Output: drush st --fields=site 328 | */ 329 | private function getCommand(InputInterface $input, OutputInterface $output): ?string { 330 | // Everything after the first "--" is treated as an argument. All such 331 | // arguments are treated as parts of the command to be executed. 332 | $command = implode(' ', $input->getArguments()['cmd']); 333 | $this->logger->debug("Command received: {command}", ['command' => $command]); 334 | 335 | if ( 336 | str_contains($command, 'drush') && 337 | !Placeholder::search($command) 338 | ) { 339 | // Inject --uri=@@dir for Drush commands without placeholders. 340 | $command = preg_replace('/\b(drush) /', 'drush --uri=@@dir ', $command, -1); 341 | $this->logger->debug('Injected --uri parameter for Drush command.'); 342 | $this->logger->notice("Command modified: {command}", ['command' => $command]); 343 | } 344 | 345 | return $command; 346 | } 347 | 348 | /** 349 | * Get unique placeholder from a command. 350 | */ 351 | private function getUniquePlaceholder(string $command): ?Placeholder { 352 | if (!$placeholders = Placeholder::search($command)) { 353 | $this->logger->error('The command contains no placeholders. Please run it directly without Drall.'); 354 | return NULL; 355 | } 356 | 357 | if (count($placeholders) > 1) { 358 | $tokens = array_column($placeholders, 'value'); 359 | $this->logger->error('The command contains: ' . implode(', ', $tokens) . '. Please use only one.'); 360 | return NULL; 361 | } 362 | 363 | return reset($placeholders); 364 | } 365 | 366 | public function getSubscribedSignals(): array { 367 | return [SIGINT]; 368 | } 369 | 370 | public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false { 371 | // If a SIGINT is received more than once, stop immediately. 372 | if ($this->isStopping) { 373 | return self::INTERRUPTED; 374 | } 375 | 376 | $this->isStopping = TRUE; 377 | return FALSE; 378 | } 379 | 380 | } 381 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Drall 2 | 3 | Drall is a tool that helps run [drush](https://www.drush.org/) commands 4 | on multi-site Drupal installations. 5 | 6 | > One command to *drush* them all. 7 | > — [Jigarius](https://jigarius.com/about) 8 | 9 | A big thanks and shout-out to [Symetris](https://symetris.ca/) for sponsoring 10 | the initial development of Drall. 11 | 12 | ## Preview 13 | 14 | ![A preview of using Drall](misc/demo.gif) 15 | 16 | ## Installation 17 | 18 | Drall is listed on [Packagist.org](https://packagist.org/packages/jigarius/drall). 19 | Thus, it can easily be installed using `composer` as follows: 20 | 21 | composer require jigarius/drall 22 | 23 | ## Placeholders 24 | 25 | Drall's functioning depends on its _Placeholders_. Here's how Drall works 26 | under the hood: 27 | 28 | 1. Receive a command, say, `drall exec -- COMMAND`. 29 | 2. Ensure there is a `@@placeholder` in `COMMAND`. 30 | 3. Run `COMMAND` after replacing `@@placeholder` with site-specific values. 31 | 4. Display the result. 32 | 33 | Drall supports the following placeholders: 34 | 35 | ### @@dir 36 | 37 | This placeholder is replaced with the name of the site's directory under 38 | Drupal's `sites` directory. These are the values of the `$sites` array 39 | usually defined in `sites.php`. 40 | 41 | ```php 42 | # @@dir is replaced with "ralph" and "leo". 43 | $sites['raphael.com'] = 'ralph'; 44 | $sites['leonardo.com'] = 'leo'; 45 | ``` 46 | 47 | **Note:** In older versions of Drall, this was called `@@uri`. 48 | 49 | ### @@key 50 | 51 | This placeholder is replaced with keys of the `$sites` array. 52 | 53 | ```php 54 | # @@key is replaced with "raphael.com", "raphael.local" and "leonardo.com". 55 | $sites['raphael.com'] = 'ralph'; 56 | $sites['raphael.local'] = 'ralph'; 57 | $sites['leonardo.com'] = 'leo'; 58 | ``` 59 | 60 | ### @@ukey 61 | 62 | This placeholder is replaced with unique keys of the `$sites` array. If a site 63 | has multiple keys, the last one is used as its unique key. 64 | 65 | ```php 66 | # @@key is replaced with "raphael.local" and "leonardo.local". 67 | $sites['raphael.com'] = 'ralph'; 68 | $sites['raphael.local'] = 'ralph'; 69 | $sites['leonardo.com'] = 'leo'; 70 | $sites['leonardo.local'] = 'leo'; 71 | ``` 72 | 73 | ### @@site 74 | 75 | This placeholder is replaced with the first part of the site's alias. 76 | 77 | ```shell 78 | # @@site is replaced with "@ralph" and "@leo". 79 | @ralph.local 80 | @leo.local 81 | ``` 82 | 83 | **Note:** This placeholder only works for sites with Drush aliases. 84 | 85 | ## Commands 86 | 87 | To see a list of commands offered by Drall, run `drall list`. If you feel lost, 88 | run `drall help` or continue reading this documentation. 89 | 90 | ### exec 91 | 92 | With `exec` you can execute drush as well as non-drush commands on multiple 93 | sites in your Drupal installation. 94 | 95 | In Drall 2.x there were 2 exec commands. These are now unified into a single 96 | command just like version 1.x. 97 | - `drall exec:drush ...` is now `drall exec -- drush ...` 98 | - `drall exec:shell ...` is now `drall exec -- ...` 99 | 100 | #### Interrupting a command 101 | 102 | When `drall exec` receives a signal to interrupt (usually `ctrl + c`), Drall 103 | stops after processing the site that is currently being processed. This 104 | prevents the current command from terminating abruptly. However, if a second 105 | interrupt signal is received, then Drall stops immediately. 106 | 107 | #### Drush with @@dir 108 | 109 | In this method, the `--uri` option is sent to `drush`. 110 | 111 | ```shell 112 | drall exec -- drush --uri=@@dir core:status 113 | ``` 114 | 115 | If it is a Drush command and no valid `@@placeholder` are present, then 116 | `--uri=@@dir` is automatically added after each occurrence of `drush`. 117 | 118 | ```shell 119 | # Raw drush command (no placeholders) 120 | drall exec -- drush core:status 121 | # Command that is executed (placeholders injected) 122 | drall exec -- drush --uri=@@dir core:status 123 | ``` 124 | 125 | ##### Example 126 | 127 | ```shell 128 | drall exec -- drush core:status 129 | ``` 130 | 131 | #### Drush with @@site 132 | 133 | In this method, a site alias is sent to `drush`. 134 | 135 | ```shell 136 | drall exec -- drush @@site.local core:status 137 | ``` 138 | 139 | ##### Example 140 | 141 | ```shell 142 | drall exec -- drush @@site.local core:status 143 | ``` 144 | 145 | #### Non-drush commands 146 | 147 | You can run non-Drush commands the same was as you run Drush commands. Just 148 | make sure that the command has valid placeholders. 149 | 150 | **Important:** You can only use any one of the possible placeholders, e.g. if 151 | you use `@@dir` and you cannot mix it with `@@site`. 152 | 153 | ##### Example: Shell command 154 | 155 | ```shell 156 | drall exec -- cat web/sites/@@uri/settings.local.php 157 | ``` 158 | 159 | ##### Example: Multiple commands 160 | 161 | ```shell 162 | drall exec "drush @@site.dev updb -y && drush @@site.dev cim -y && drush @@site.dev cr" 163 | ``` 164 | 165 | #### Options 166 | 167 | For the `drall exec` command, all Drall options must be set right after 168 | `drall exec`. Additionally, `--` must be used before the command to be 169 | executed. Following are some examples of running `drush` with options. 170 | 171 | ```shell 172 | # Drall is --verbose 173 | drall exec --verbose -- drush core:status 174 | # Drush is verbose 175 | drall exec -- drush --verbose core:status 176 | # Both Drall and Drush are --verbose 177 | drall exec --verbose -- drush --verbose core:status 178 | ``` 179 | 180 | In summary, the syntax is as follows: 181 | 182 | ```shell 183 | drall exec [DRALL-OPTIONS] -- drush [DRUSH-OPTIONS] 184 | ``` 185 | 186 | Besides the global options, the `exec` command supports the following options. 187 | 188 | #### --interval 189 | 190 | This option makes Drall wait for `n` seconds after processing each item. 191 | 192 | ```shell 193 | drall exec --interval=3 -- drush core:rebuild 194 | ``` 195 | 196 | Such an interval cannot be used when using a multiple workers. 197 | 198 | #### --workers 199 | 200 | Say you have 100 sites in a Drupal installation. By default, Drall runs 201 | commands on these sites one after the other. To speed up the execution, you 202 | can ask Drall to execute multiple commands in parallel. You can specify the 203 | number of workers with the `--workers=n` option, where `n` is the 204 | number of processes you want to run in parallel. 205 | 206 | Please keep in mind that the performance of the workers depends on your 207 | resources available on the computer executing the command. If you have low 208 | memory, and you run Drall with 4 workers, performance might suffer. Also, 209 | some operations need to be executed sequentially to avoid competition and 210 | conflict between the Drall workers. 211 | 212 | ##### Example: Parallel execution 213 | 214 | The command below launches 3 instances of Drall to run `core:rebuild` command. 215 | 216 | ```shell 217 | drall exec --workers=3 -- drush core:rebuild 218 | ``` 219 | 220 | When a worker runs out of work, it terminates automatically. 221 | 222 | #### --no-progress 223 | 224 | By default, Drall displays a progress bar that indicates how many sites have 225 | been processed and how many are remaining. In verbose mode, this progress 226 | indicator also displays the time elapsed. 227 | 228 | However, the progress display that can mess with some terminals or scripts 229 | which don't handle backspace characters. For these environments, the progress 230 | bar can be disabled using the `--no-progress` option. 231 | 232 | ##### Example: Hide progress bar 233 | 234 | ```shell 235 | drall exec --no-progress -- drush core:rebuild 236 | ``` 237 | 238 | #### --dry-run 239 | 240 | This option allows you to see what commands will be executed without actually 241 | executing them. 242 | 243 | ##### Example: Dry run 244 | 245 | ```shell 246 | drall exec --dry-run --group=bluish -- drush core:status 247 | ``` 248 | 249 | ### site:directories 250 | 251 | Get a list of all available site directory names in the Drupal installation. 252 | All `sites/*` directories containing a `settings.php` file are treated as 253 | individual sites. 254 | 255 | #### Example: Usage 256 | 257 | ```shell 258 | drall site:directories 259 | ``` 260 | 261 | The output can then be iterated with scripts. 262 | 263 | #### Example: Iterating 264 | 265 | ```shell 266 | for site in $(drall site:directories) 267 | do 268 | echo "Current site: $site"; 269 | done; 270 | ``` 271 | 272 | ### site:keys 273 | 274 | Get a list of all keys in `$sites`. Usually, these are site URIs. 275 | 276 | #### Example: Usage 277 | 278 | ```shell 279 | drall site:keys 280 | ``` 281 | 282 | The output can then be iterated with scripts. 283 | 284 | #### Example: Iterating 285 | 286 | ```shell 287 | for site in $(drall site:keys) 288 | do 289 | echo "Current site: $site"; 290 | done; 291 | ``` 292 | 293 | ### site:aliases 294 | 295 | Get a list of site aliases. 296 | 297 | #### Example: Usage 298 | 299 | ```shell 300 | drall site:aliases 301 | ``` 302 | 303 | The output can then be iterated with scripts. 304 | 305 | #### Example: Iterating 306 | 307 | ```shell 308 | for site in $(drall site:aliases) 309 | do 310 | echo "Current site: $site"; 311 | done; 312 | ``` 313 | 314 | ## Global options 315 | 316 | This section covers some options that are supported by all `drall` commands. 317 | 318 | ### --group 319 | 320 | Specify the target site group. See the section *site groups* for more 321 | information on site groups. 322 | 323 | ```shell 324 | drall exec --group=GROUP -- drush core:status --field=site 325 | ``` 326 | 327 | If `--group` is not set, then the Drall uses the environment variable 328 | `DRALL_GROUP`, if it is set. 329 | 330 | ### --filter 331 | 332 | Filter placeholder values with an expression. This is helpful for running 333 | commands on specific sites. 334 | 335 | ```shell 336 | # Run only on the "leo" site. 337 | drall exec --filter=leo -- drush core:status 338 | # Run only on "leo" and "ralph" sites. 339 | drall exec --filter="leo||ralph" -- drush core:status 340 | ``` 341 | 342 | For more on using filter expressions, refer to the documentation on 343 | [consolidation/filter-via-dot-access-data](https://github.com/consolidation/filter-via-dot-access-data). 344 | 345 | ### --offset 346 | 347 | An integer indicating the number of items to skip from the beginning. If a 348 | negative integer is provided it is treated as `n - o`, where `n` is the total 349 | number of items and `o` is the offset. 350 | 351 | ```shell 352 | # Skip the first 2 items. 353 | drall exec --offset=2 -- drush core:status 354 | # Start at the 2nd item from the end. 355 | drall exec --offset=-2 -- drush core:status 356 | ``` 357 | 358 | ### --limit 359 | 360 | An integer indicating the number of items to process. 361 | 362 | ```shell 363 | # Stop after the first 2 items. 364 | drall exec --limit=2 -- drush core:status 365 | # Skip the first 2 items and process 3 items thereafter. Thus, only items 366 | # 3, 4, 5 are processed. 367 | drall exec --offset=2 --limit=3 -- drush core:status 368 | ``` 369 | 370 | ### --silent 371 | 372 | Display no output. 373 | 374 | ### --quiet 375 | 376 | Display very less output. 377 | 378 | ### --verbose 379 | 380 | Display verbose output. 381 | 382 | ### --debug 383 | 384 | Display very verbose output. 385 | 386 | ## Auto-detect sites 387 | 388 | Drall uses `sites.php` to determine site hostnames and site directories. 389 | However, some Drupal multi-site installations do not have a `sites.php` 390 | because the content of the `DRUPAL/sites` directory changes very frequently, 391 | thereby making it difficult to maintain such a `sites.php`. 392 | 393 | In such cases, it is suggested that you create a `DRUPAL/sites/sites.php` 394 | based on [misc/example.sites.php](misc/example.sites.php) so that Drall can 395 | detect the sites in your Drupal installation. Additionally, in this file you 396 | can alter the `$sites` variable based on your requirements. 397 | 398 | ## Site groups 399 | 400 | Drall allows you to group your sites so that you can run commands on these 401 | groups using the `--group` option. 402 | 403 | ### Drall groups with site aliases 404 | 405 | In a site alias definition file, you can assign site aliases to one or more 406 | groups like this: 407 | 408 | ```yaml 409 | # File: tnmt.site.yml 410 | local: 411 | root: /opt/drupal/web 412 | uri: https://tmnt.com/ 413 | # ... 414 | drall: 415 | groups: 416 | - cartoon 417 | - action 418 | ``` 419 | 420 | This puts the alias `@tnmt.local` in the `cartoon` and `action` groups. 421 | 422 | ### Drall groups with sites.*.php 423 | 424 | If your project doesn't use site aliases, you can still group your sites using 425 | one or more `sites.GROUP.php` files like this: 426 | 427 | ```php 428 | # File: sites.bluish.php 429 | $sites['donnie.drall.local'] = 'donnie'; 430 | $sites['leo.drall.local'] = 'leo'; 431 | ``` 432 | 433 | This puts the sites `donnie` and `leo` in a group named `bluish`. 434 | 435 | ## Development 436 | 437 | Here's how you can set up a local dev environment. 438 | 439 | - Clone the `https://github.com/jigarius/drall` repository. 440 | - Use a branch as per your needs. 441 | - Run `docker compose up -d`. 442 | - Run `docker compose start`. 443 | - Run `make ssh` to launch a shell in the Drupal container. 444 | - Run `make provision`. 445 | - Run `drall --version` to test the setup. 446 | - Run `make lint` to run linter. 447 | - Run `make test` to run tests. 448 | 449 | You should now be able to `make ssh` and then run `drall`. A multi-site Drupal 450 | installation should be present at `/opt/drupal`. Oh! And Drall should be 451 | present at `/opt/drall`. 452 | 453 | ### Hosts 454 | 455 | To access the dev sites in your browser, add the following line to your hosts 456 | file. It is usually located at `/etc/hosts`. This is completely optional, so 457 | do this only if you need it. 458 | 459 | 127.0.0.1 tmnt.drall.local donnie.drall.local leo.drall.local mikey.drall.local ralph.drall.local 460 | 461 | The sites should then be available at: 462 | - [tmnt.drall.local](http://tmnt.drall.local/) 463 | - [donnie.drall.local](http://donnie.drall.local/) 464 | - [leo.drall.local](http://leo.drall.local/) 465 | - [mikey.drall.local](http://mikey.drall.local/) 466 | - [ralph.drall.local](http://ralph.drall.local/) 467 | 468 | ## Acknowledgements 469 | 470 | - Thanks, [Symetris](https://symetris.ca/) for funding the initial development. 471 | - Thanks, [Jigarius](https://jigarius.com/about) (that's me) for spending 472 | evenings and weekends to make this tool possible. 473 | -------------------------------------------------------------------------------- /test/Integration/Command/ExecCommandTest.php: -------------------------------------------------------------------------------- 1 | run(); 27 | $this->assertOutputEquals(<<getOutput()); 34 | $this->assertOutputContainsString('Missing options separator', $process->getErrorOutput()); 35 | $this->assertEquals(1, $process->getExitCode()); 36 | } 37 | 38 | /** 39 | * @testdox Shows error when --drall-* options are detected. 40 | */ 41 | public function testShowErrorForObsoleteOptions(): void { 42 | $process = Process::fromShellCommandline('./vendor/bin/drall exec -P --drall-foo drush st', static::PATH_DRUPAL); 43 | $process->run(); 44 | $this->assertOutputEquals(<<getOutput()); 49 | $this->assertOutputContainsString('Obsolete options detected', $process->getErrorOutput()); 50 | $this->assertEquals(1, $process->getExitCode()); 51 | } 52 | 53 | /** 54 | * @testdox With no Drupal installation. 55 | */ 56 | public function testWithNoDrupal(): void { 57 | $process = Process::fromShellCommandline( 58 | 'drall exec -P -- ./vendor/bin/drush --uri=@@dir core:status', 59 | static::PATH_NO_DRUPAL, 60 | ); 61 | $process->run(); 62 | $this->assertStringContainsString('Package "drupal/core" is not installed', $process->getErrorOutput()); 63 | 64 | $process = Process::fromShellCommandline( 65 | 'drall exec --no-progress -- ./vendor/bin/drush @@site.local core:status', 66 | static::PATH_NO_DRUPAL, 67 | ); 68 | $process->run(); 69 | $this->assertStringContainsString('Package "drupal/core" is not installed', $process->getErrorOutput()); 70 | } 71 | 72 | /** 73 | * @testdox With an empty Drupal installation. 74 | */ 75 | public function testWithEmptyDrupal(): void { 76 | $process = Process::fromShellCommandline( 77 | 'drall exec --no-progress -- ./vendor/bin/drush --uri=@@dir core:status', 78 | static::PATH_EMPTY_DRUPAL, 79 | ); 80 | $process->run(); 81 | $this->assertOutputEquals('[warning] No Drupal sites found.' . PHP_EOL, $process->getOutput()); 82 | 83 | $process = Process::fromShellCommandline( 84 | 'drall exec --no-progress -- ./vendor/bin/drush @@site.local core:status', 85 | static::PATH_EMPTY_DRUPAL, 86 | ); 87 | $process->run(); 88 | $this->assertOutputEquals('[warning] No Drupal sites found.' . PHP_EOL, $process->getOutput()); 89 | } 90 | 91 | /** 92 | * @testdox Raises error for non-Drush command with no placeholders. 93 | */ 94 | public function testNonDrushWithNoPlaceholders(): void { 95 | $process = Process::fromShellCommandline('drall exec --no-progress -- foo', static::PATH_DRUPAL); 96 | $process->run(); 97 | $this->assertOutputEquals( 98 | '[error] The command contains no placeholders. Please run it directly without Drall.' . PHP_EOL, 99 | $process->getErrorOutput(), 100 | ); 101 | } 102 | 103 | /** 104 | * @testdox Working directory. 105 | */ 106 | public function testWorkingDirectory(): void { 107 | $process = Process::fromShellCommandline( 108 | 'drall exec --no-progress --filter=tmnt -- "echo \"Site: @@site\" && pwd"', 109 | static::PATH_DRUPAL, 110 | ); 111 | $process->run(); 112 | $this->assertOutputEquals(<<getOutput()); 118 | } 119 | 120 | /** 121 | * @testdox With @@dir. 122 | */ 123 | public function testDrushWithUriPlaceholder(): void { 124 | $process = Process::fromShellCommandline( 125 | 'drall exec --no-progress -- ./vendor/bin/drush --uri=@@dir core:status --field=site', 126 | static::PATH_DRUPAL, 127 | ); 128 | $process->run(); 129 | $this->assertOutputEquals(<<getOutput()); 142 | } 143 | 144 | /** 145 | * @testdox With @@site. 146 | */ 147 | public function testDrushWithSitePlaceholder(): void { 148 | $process = Process::fromShellCommandline( 149 | 'drall exec --no-progress -- ./vendor/bin/drush @@site.local core:status --field=site', 150 | static::PATH_DRUPAL, 151 | ); 152 | $process->run(); 153 | $this->assertOutputEquals(<<getOutput()); 166 | } 167 | 168 | /** 169 | * @testdox Injects --uri for Drush command with no placeholders. 170 | */ 171 | public function testDrushWithNoPlaceholders(): void { 172 | $process = Process::fromShellCommandline( 173 | 'drall exec --no-progress -- ./vendor/bin/drush core:status --field=site', 174 | static::PATH_DRUPAL, 175 | ); 176 | $process->run(); 177 | $this->assertOutputEquals(<<getOutput()); 190 | } 191 | 192 | /** 193 | * @testdox With multiple drush commands and no placeholders. 194 | */ 195 | public function testMultipleDrushWithNoPlaceholders(): void { 196 | $process = Process::fromShellCommandline( 197 | 'drall exec --no-progress -- "./vendor/bin/drush st --fields=site; ./vendor/bin/drush st --fields=uri"', 198 | static::PATH_DRUPAL, 199 | ); 200 | $process->run(); 201 | $this->assertOutputEquals(<<getOutput()); 219 | } 220 | 221 | /** 222 | * @testdox With no placeholders and "drush" present in a path. 223 | */ 224 | public function testDrushInPath(): void { 225 | $process = Process::fromShellCommandline( 226 | 'drall exec --no-progress -- ls ./vendor/drush/src', 227 | static::PATH_DRUPAL, 228 | ); 229 | $process->run(); 230 | $this->assertOutputEquals( 231 | '[error] The command contains no placeholders. Please run it directly without Drall.' . PHP_EOL, 232 | $process->getErrorOutput(), 233 | ); 234 | } 235 | 236 | /** 237 | * @testdox With Drush capitalized. 238 | * 239 | * If for some reason someone needs to write the word Drush, it won't be 240 | * appended with --uri if it is capitalized. 241 | */ 242 | public function testDrushCapitalized(): void { 243 | $process = Process::fromShellCommandline( 244 | 'drall exec --no-progress -- "echo \"Drush status\" && ./vendor/bin/drush st --fields=site"', 245 | static::PATH_DRUPAL, 246 | ); 247 | $process->run(); 248 | $this->assertOutputEquals(<<getOutput()); 266 | } 267 | 268 | /** 269 | * @testdox With mixed placeholders. 270 | */ 271 | public function testWithMixedPlaceholders(): void { 272 | $process = Process::fromShellCommandline( 273 | 'drall exec --no-progress -- "./vendor/bin/drush --uri=@@dir st && ./vendor/bin/drush @@site.local st"', 274 | static::PATH_DRUPAL, 275 | ); 276 | $process->run(); 277 | $this->assertOutputEquals( 278 | '[error] The command contains: @@site, @@dir. Please use only one.' . PHP_EOL, 279 | $process->getErrorOutput(), 280 | ); 281 | } 282 | 283 | /** 284 | * @testdox With @@dir placeholder. 285 | */ 286 | public function testWithDirPlaceholder(): void { 287 | $process = Process::fromShellCommandline( 288 | 'drall exec --no-progress -- ls web/sites/@@dir/settings.php', 289 | static::PATH_DRUPAL, 290 | ); 291 | $process->run(); 292 | $this->assertOutputEquals(<<getOutput()); 305 | } 306 | 307 | /** 308 | * @testdox With --filter. 309 | */ 310 | public function testWithFilter(): void { 311 | $process1 = Process::fromShellCommandline( 312 | 'drall exec --no-progress --filter=leo -- ./vendor/bin/drush st --field=site', 313 | static::PATH_DRUPAL, 314 | ); 315 | $process1->run(); 316 | $this->assertOutputEquals(<<getOutput()); 321 | 322 | // Short form. 323 | $process2 = Process::fromShellCommandline( 324 | 'drall exec --no-progress -f leo -- ./vendor/bin/drush st --field=site', 325 | static::PATH_DRUPAL, 326 | ); 327 | $process2->run(); 328 | $this->assertOutputEquals(<<getOutput()); 333 | } 334 | 335 | /** 336 | * @testdox With --group. 337 | */ 338 | public function testWithGroup(): void { 339 | $process1 = Process::fromShellCommandline( 340 | 'drall exec --no-progress --group=bluish -- ./vendor/bin/drush st --field=site', 341 | static::PATH_DRUPAL, 342 | ); 343 | $process1->run(); 344 | $this->assertOutputEquals(<<getOutput()); 351 | 352 | // Short form. 353 | $process2 = Process::fromShellCommandline( 354 | 'drall exec --no-progress -g bluish -- ./vendor/bin/drush st --field=site', 355 | static::PATH_DRUPAL, 356 | ); 357 | $process2->run(); 358 | $this->assertOutputEquals(<<getOutput()); 365 | } 366 | 367 | /** 368 | * @testdox With --offset. 369 | */ 370 | public function testWithOffset(): void { 371 | $process = Process::fromShellCommandline( 372 | 'drall exec --no-progress --offset=3 -- ./vendor/bin/drush st --field=site', 373 | static::PATH_DRUPAL, 374 | ); 375 | $process->run(); 376 | $this->assertOutputEquals(<<getOutput()); 383 | 384 | // Negative offsets like -2 select the last 2 sites. 385 | $process = Process::fromShellCommandline( 386 | 'drall exec --no-progress --offset=-2 -- ./vendor/bin/drush st --field=site', 387 | static::PATH_DRUPAL, 388 | ); 389 | $process->run(); 390 | $this->assertOutputEquals(<<getOutput()); 397 | } 398 | 399 | /** 400 | * @testdox With --limit. 401 | */ 402 | public function testWithLimit(): void { 403 | $process1 = Process::fromShellCommandline( 404 | 'drall exec --no-progress --limit=1 -- ./vendor/bin/drush st --field=site', 405 | static::PATH_DRUPAL, 406 | ); 407 | $process1->run(); 408 | $this->assertOutputEquals(<<getOutput()); 413 | } 414 | 415 | /** 416 | * @testdox With --offset and --limit. 417 | */ 418 | public function testWithRange(): void { 419 | $process1 = Process::fromShellCommandline( 420 | 'drall exec --no-progress --offset=2 --limit=2 -- ./vendor/bin/drush st --field=site', 421 | static::PATH_DRUPAL, 422 | ); 423 | $process1->run(); 424 | $this->assertOutputEquals(<<getOutput()); 431 | } 432 | 433 | /** 434 | * @testdox with DRALL_GROUP env var. 435 | */ 436 | public function testWithGroupEnvVar(): void { 437 | $process = Process::fromShellCommandline( 438 | 'drall exec --no-progress -- ./vendor/bin/drush st --field=site', 439 | static::PATH_DRUPAL, 440 | ['DRALL_GROUP' => 'bluish'], 441 | ); 442 | $process->run(); 443 | $this->assertOutputEquals(<<getOutput()); 450 | } 451 | 452 | /** 453 | * @testdox With @@site placeholder. 454 | */ 455 | public function testWithSitePlaceholder(): void { 456 | $process = Process::fromShellCommandline( 457 | 'drall exec --no-progress ./vendor/bin/drush -- @@site.local core:status --fields=site', 458 | static::PATH_DRUPAL, 459 | ); 460 | $process->run(); 461 | $this->assertOutputEquals(<<getOutput()); 474 | } 475 | 476 | /** 477 | * @testdox With @@site placeholder and --group. 478 | */ 479 | public function testWithSitePlaceholderAndGroup(): void { 480 | $process = Process::fromShellCommandline( 481 | 'drall exec --no-progress --group=bluish -- ./vendor/bin/drush @@site.local st --field=site', 482 | static::PATH_DRUPAL, 483 | ); 484 | $process->run(); 485 | $this->assertOutputEquals(<<getOutput()); 492 | } 493 | 494 | /** 495 | * @testdox Catch STDERR output. 496 | */ 497 | public function testCatchStdErrOutput(): void { 498 | $process = Process::fromShellCommandline( 499 | 'drall exec --no-progress --filter=default -- ./vendor/bin/drush --verbose version', 500 | static::PATH_DRUPAL, 501 | ); 502 | $process->run(); 503 | 504 | // Ignore the Drush Version. 505 | $output = preg_replace('@(Drush version :) ([\d|\.|-]+)@', '$1 x.y.z', $process->getOutput()); 506 | 507 | $this->assertOutputEquals(<<&1', 523 | static::PATH_DRUPAL, 524 | ); 525 | $process->run(); 526 | $this->assertOutputEquals(<<----------------------] 20%sites/donnie 530 | ✔ donnie: Done 531 | 2/5 [===========>----------------] 40%sites/leo 532 | ✔ leo: Done 533 | 3/5 [================>-----------] 60%sites/mikey 534 | ✔ mikey: Done 535 | 4/5 [======================>-----] 80%sites/ralph 536 | ✔ ralph: Done 537 | 5/5 [============================] 100% 538 | EOF, $process->getOutput()); 539 | } 540 | 541 | /** 542 | * @testdox With no buffer. 543 | */ 544 | public function testWithNoBuffer(): void { 545 | $process = Process::fromShellCommandline( 546 | 'drall exec --no-progress --no-buffer --verbose -- ./vendor/bin/drush st --field=site 2>&1', 547 | static::PATH_DRUPAL, 548 | ); 549 | $process->run(); 550 | $this->assertStringStartsWith( 551 | '[notice] Using no output buffering.' . PHP_EOL, 552 | $process->getOutput(), 553 | ); 554 | } 555 | 556 | /** 557 | * @testdox With verbosity quiet. 558 | */ 559 | public function testWithVerbosityQuiet(): void { 560 | $process1 = Process::fromShellCommandline( 561 | 'drall exec --no-progress --quiet -- ./vendor/bin/drush st --field=site', 562 | static::PATH_DRUPAL, 563 | ); 564 | $process1->run(); 565 | $this->assertEquals(<<getOutput()); 573 | 574 | // Short form. 575 | $process2 = Process::fromShellCommandline( 576 | 'drall exec --no-progress -q -- ./vendor/bin/drush st --field=site', 577 | static::PATH_DRUPAL, 578 | ); 579 | $process2->run(); 580 | $this->assertEquals(<<getOutput()); 588 | } 589 | 590 | /** 591 | * @testdox With --dry-run. 592 | */ 593 | public function testWithDryRun(): void { 594 | $process1 = Process::fromShellCommandline( 595 | 'drall exec --no-progress --dry-run -- ./vendor/bin/drush st', 596 | static::PATH_DRUPAL, 597 | ); 598 | $process1->run(); 599 | $this->assertOutputEquals(<<getOutput()); 607 | 608 | // Short form. 609 | $process2 = Process::fromShellCommandline( 610 | 'drall exec --no-progress -X -- ./vendor/bin/drush st', 611 | static::PATH_DRUPAL, 612 | ); 613 | $process2->run(); 614 | $this->assertOutputEquals(<<getOutput()); 622 | } 623 | 624 | /** 625 | * @testdox Shows error when --interval is negative. 626 | */ 627 | public function testNegativeInterval(): void { 628 | $process = Process::fromShellCommandline( 629 | 'drall ex --interval=-3 -- drush st --fields=site', 630 | static::PATH_DRUPAL, 631 | ); 632 | $process->run(); 633 | $this->assertOutputEquals(<<getOutput()); 637 | $this->assertOutputContainsString('Invalid options detected', $process->getErrorOutput()); 638 | $this->assertEquals(1, $process->getExitCode()); 639 | } 640 | 641 | /** 642 | * @testdox With --interval. 643 | */ 644 | public function testWithInterval(): void { 645 | $process = Process::fromShellCommandline( 646 | 'drall ex --interval=2 --verbose -- ./vendor/bin/drush st --fields=site', 647 | static::PATH_DRUPAL, 648 | ); 649 | $process->run(); 650 | $this->assertOutputContainsString( 651 | '[notice] Using a 2-second interval between commands.' . PHP_EOL, 652 | $process->getOutput(), 653 | ); 654 | 655 | // The command must take 2 * count($sites) seconds. 656 | // This confirms that the sleep(2) command is actually executed. 657 | $timeTaken = microtime(TRUE) - $process->getStartTime(); 658 | $this->assertGreaterThan(10, $timeTaken); 659 | } 660 | 661 | /** 662 | * @testdox With --workers=2. 663 | */ 664 | public function testWithWorkers(): void { 665 | // The "default" item, takes 3+ seconds to execute during which the second 666 | // worker processes all other items. Finally, "default" finishes last. 667 | $process1 = Process::fromShellCommandline( 668 | "drall ex --no-progress --workers=2 --verbose -- \"if [ 'default' = '@@dir' ]; then sleep 3; fi; echo 'Hello @@dir.';\"", 669 | static::PATH_DRUPAL, 670 | ); 671 | $process1->run(); 672 | 673 | $this->assertOutputEquals(<<getOutput()); 687 | 688 | // Short form. 689 | $process2 = Process::fromShellCommandline( 690 | 'drall ex -w2 --verbose -- drush --uri=@@dir core:status --fields=site', 691 | static::PATH_DRUPAL, 692 | ); 693 | $process2->run(); 694 | 695 | $this->assertStringStartsWith( 696 | '[notice] Using 2 workers.', 697 | $process2->getOutput(), 698 | ); 699 | } 700 | 701 | /** 702 | * @testdox Shows error when --worker limit exceeds the maximum. 703 | */ 704 | public function testWorkerLimit(): void { 705 | $process = Process::fromShellCommandline( 706 | 'drall ex --workers=17 -- drush st --fields=site', 707 | static::PATH_DRUPAL, 708 | ); 709 | $process->run(); 710 | $this->assertOutputEquals(<<getOutput()); 714 | $this->assertOutputContainsString('Invalid options detected', $process->getErrorOutput()); 715 | $this->assertEquals(1, $process->getExitCode()); 716 | } 717 | 718 | /** 719 | * @testdox Shows error when --workers and --interval are used together. 720 | */ 721 | public function testIntervalWithWorkers(): void { 722 | $process = Process::fromShellCommandline( 723 | 'drall ex --workers=2 --interval=2 -- drush st --fields=site', 724 | static::PATH_DRUPAL, 725 | ); 726 | $process->run(); 727 | $this->assertOutputEquals(<<getOutput()); 731 | $this->assertOutputContainsString('Incompatible options detected', $process->getErrorOutput()); 732 | $this->assertEquals(1, $process->getExitCode()); 733 | } 734 | 735 | /** 736 | * @testdox Exits with non-zero code if any command fails. 737 | */ 738 | public function testNonZeroExitCode(): void { 739 | $process = Process::fromShellCommandline( 740 | "drall exec -P -- \"if [ 'default' = '@@dir' ]; then exit 1; fi; echo 'Hello @@dir.';\"", 741 | static::PATH_DRUPAL, 742 | ); 743 | $process->run(); 744 | $this->assertOutputEquals(<<getOutput()); 756 | $this->assertEquals(1, $process->getExitCode()); 757 | } 758 | 759 | /** 760 | * @testdox One SIGINT gives a graceful exit. 761 | */ 762 | public function testSigInt1(): void { 763 | $this->markTestSkipped('Needs work.'); 764 | } 765 | 766 | /** 767 | * @testdox Two SIGINT gives a forceful exit. 768 | */ 769 | public function testSigInt2(): void { 770 | $this->markTestSkipped('Needs work.'); 771 | } 772 | 773 | } 774 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------