diff --git a/doc/tasks/shell.md b/doc/tasks/shell.md index 92aed389..e7cc017e 100644 --- a/doc/tasks/shell.md +++ b/doc/tasks/shell.md @@ -10,6 +10,7 @@ grumphp: shell: scripts: [] triggered_by: [php] + triggered_by_filenames: [] ``` **scripts** @@ -41,5 +42,14 @@ grumphp: *Default: [php]* This option will specify which file extensions will trigger the shell tasks. -By default, Shell will be triggered by altering a PHP file. +By default, Shell will be triggered by altering a PHP file. +You can overwrite this option to whatever file you want to use! + + +**triggered_by_filenames** + +*Default: []* + +This option will specify which files will trigger the shell tasks. +By default, Shell will not be triggered by specific files. You can overwrite this option to whatever file you want to use! diff --git a/src/Task/AbstractParserTask.php b/src/Task/AbstractParserTask.php index c40c4b90..86abf147 100644 --- a/src/Task/AbstractParserTask.php +++ b/src/Task/AbstractParserTask.php @@ -50,10 +50,12 @@ protected static function sharedOptionsResolver(): OptionsResolver $resolver = new OptionsResolver(); $resolver->setDefaults([ 'triggered_by' => [], + 'triggered_by_filenames' => [], 'ignore_patterns' => [], ]); $resolver->addAllowedTypes('triggered_by', ['array']); + $resolver->addAllowedTypes('triggered_by_filenames', ['array']); $resolver->addAllowedTypes('ignore_patterns', ['array']); return $resolver; diff --git a/src/Task/Shell.php b/src/Task/Shell.php index ab4b1f6c..eb7b1b66 100644 --- a/src/Task/Shell.php +++ b/src/Task/Shell.php @@ -4,6 +4,7 @@ namespace GrumPHP\Task; +use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; use GrumPHP\Formatter\ProcessFormatterInterface; use GrumPHP\Runner\TaskResult; @@ -26,6 +27,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver $resolver->setDefaults([ 'scripts' => [], 'triggered_by' => ['php'], + 'triggered_by_filenames' => [], ]); $resolver->addAllowedTypes('scripts', ['array']); @@ -59,7 +61,12 @@ public function canRunInContext(ContextInterface $context): bool public function run(ContextInterface $context): TaskResultInterface { $config = $this->getConfig()->getOptions(); - $files = $context->getFiles()->extensions($config['triggered_by']); + $files = new FilesCollection( + array_merge( + $context->getFiles()->extensions($config['triggered_by'])->toArray(), + $context->getFiles()->names($config['triggered_by_filenames'])->toArray(), + ) + ); if (0 === \count($files)) { return TaskResult::createSkipped($this, $context); } diff --git a/test/Unit/Task/ShellTest.php b/test/Unit/Task/ShellTest.php index 458ed48e..c7d93765 100644 --- a/test/Unit/Task/ShellTest.php +++ b/test/Unit/Task/ShellTest.php @@ -27,6 +27,7 @@ public function provideConfigurableOptions(): iterable [ 'scripts' => [], 'triggered_by' => ['php'], + 'triggered_by_filenames' => [], ] ]; yield 'string_script' => [ @@ -38,6 +39,7 @@ public function provideConfigurableOptions(): iterable ['phpunit'] ], 'triggered_by' => ['php'], + 'triggered_by_filenames' => [], ] ]; yield 'array_script' => [ @@ -51,6 +53,7 @@ public function provideConfigurableOptions(): iterable ['phpunit', 'tests'] ], 'triggered_by' => ['php'], + 'triggered_by_filenames' => [], ] ]; }