From 31c6e56f563ea9ecbbf8bf9716245754b5b644e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Poirier=20Th=C3=A9or=C3=AAt?= Date: Mon, 13 Nov 2023 08:50:56 -0500 Subject: [PATCH] [Console] Filter in/out support --- config/packages/draw_framework_extra.yaml | 3 +- ...ocumentationFilterCommandEventListener.php | 32 +++++ ...cumentationIgnoredCommandEventListener.php | 21 ---- .../Integration/ConsoleIntegration.php | 17 ++- .../Integration/ConsoleIntegrationTest.php | 18 ++- .../testExecution_expectedExport.md | 113 ------------------ 6 files changed, 57 insertions(+), 147 deletions(-) create mode 100644 packages/framework-extra-bundle/Console/EventListener/DocumentationFilterCommandEventListener.php delete mode 100644 packages/framework-extra-bundle/Console/EventListener/DocumentationIgnoredCommandEventListener.php diff --git a/config/packages/draw_framework_extra.yaml b/config/packages/draw_framework_extra.yaml index 3e415f70..7635e75d 100644 --- a/config/packages/draw_framework_extra.yaml +++ b/config/packages/draw_framework_extra.yaml @@ -7,7 +7,8 @@ draw_framework_extra: console: documentation: - ignored_commands: [ 'completion', 'help', 'list' ] + filter: 'in' + command_names: [ 'draw:console:generate-documentation' ] doctrine_extra: ~ diff --git a/packages/framework-extra-bundle/Console/EventListener/DocumentationFilterCommandEventListener.php b/packages/framework-extra-bundle/Console/EventListener/DocumentationFilterCommandEventListener.php new file mode 100644 index 00000000..5e3d4113 --- /dev/null +++ b/packages/framework-extra-bundle/Console/EventListener/DocumentationFilterCommandEventListener.php @@ -0,0 +1,32 @@ +getCommand()->getName(), $this->commandNames); + + if ($match && self::FILTER_OUT === $this->filter) { + $event->ignore(); + + return; + } + + if (!$match && self::FILTER_IN === $this->filter) { + $event->ignore(); + } + } +} diff --git a/packages/framework-extra-bundle/Console/EventListener/DocumentationIgnoredCommandEventListener.php b/packages/framework-extra-bundle/Console/EventListener/DocumentationIgnoredCommandEventListener.php deleted file mode 100644 index c291ad27..00000000 --- a/packages/framework-extra-bundle/Console/EventListener/DocumentationIgnoredCommandEventListener.php +++ /dev/null @@ -1,21 +0,0 @@ -getCommand()->getName(), $this->ignoredCommandNames)) { - $event->ignore(); - } - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Integration/ConsoleIntegration.php b/packages/framework-extra-bundle/DependencyInjection/Integration/ConsoleIntegration.php index 409f9a4b..73140f96 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Integration/ConsoleIntegration.php +++ b/packages/framework-extra-bundle/DependencyInjection/Integration/ConsoleIntegration.php @@ -2,7 +2,7 @@ namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration; -use Draw\Bundle\FrameworkExtraBundle\Console\EventListener\DocumentationIgnoredCommandEventListener; +use Draw\Bundle\FrameworkExtraBundle\Console\EventListener\DocumentationFilterCommandEventListener; use Draw\Bundle\FrameworkExtraBundle\DrawFrameworkExtraBundle; use Draw\Component\Console\Command\PurgeExecutionCommand; use Draw\Component\Console\Entity\Execution; @@ -50,9 +50,14 @@ public function load(array $config, PhpFileLoader $loader, ContainerBuilder $con \dirname((new \ReflectionClass(DrawFrameworkExtraBundle::class))->getFileName()).'/Console' ); - $container - ->getDefinition(DocumentationIgnoredCommandEventListener::class) - ->setArgument('$ignoredCommandNames', $config['documentation']['ignored_commands']); + if (!$config['documentation']['command_names']) { + $container->removeDefinition(DocumentationFilterCommandEventListener::class); + } else { + $container + ->getDefinition(DocumentationFilterCommandEventListener::class) + ->setArgument('$commandNames', $config['documentation']['command_names']) + ->setArgument('$filter', $config['documentation']['filter']); + } $this->renameDefinitions( $container, @@ -69,8 +74,8 @@ public function addConfiguration(ArrayNodeDefinition $node): void ->arrayNode('documentation') ->addDefaultsIfNotSet() ->children() - ->arrayNode('ignored_commands') - ->defaultValue([]) + ->enumNode('filter')->values(['in', 'out'])->defaultValue('in')->end() + ->arrayNode('command_names') ->scalarPrototype()->end() ->end() ->end() diff --git a/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/ConsoleIntegrationTest.php b/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/ConsoleIntegrationTest.php index 8a860ef5..8d22063b 100644 --- a/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/ConsoleIntegrationTest.php +++ b/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/ConsoleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Draw\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\Integration; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; -use Draw\Bundle\FrameworkExtraBundle\Console\EventListener\DocumentationIgnoredCommandEventListener; +use Draw\Bundle\FrameworkExtraBundle\Console\EventListener\DocumentationFilterCommandEventListener; use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\ConsoleIntegration; use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\IntegrationInterface; use Draw\Component\Console\Command\GenerateDocumentationCommand; @@ -35,7 +35,8 @@ public function getDefaultConfiguration(): array return [ 'ignore_disabled_command' => false, 'documentation' => [ - 'ignored_commands' => [], + 'filter' => 'in', + 'command_names' => [], ], ]; } @@ -92,7 +93,8 @@ public static function provideTestLoad(): iterable [ 'ignore_disabled_command' => true, 'documentation' => [ - 'ignored_commands' => [ + 'filter' => 'out', + 'command_names' => [ 'help', ], ], @@ -123,14 +125,18 @@ function (Definition $definition): void { } ), new ServiceConfiguration( - 'draw.console.event_listener.documentation_ignored_command_event_listener', + 'draw.console.event_listener.documentation_filter_command_event_listener', [ - DocumentationIgnoredCommandEventListener::class, + DocumentationFilterCommandEventListener::class, ], function (Definition $definition): void { + static::assertSame( + 'out', + $definition->getArgument('$filter') + ); static::assertSame( ['help'], - $definition->getArgument('$ignoredCommandNames') + $definition->getArgument('$commandNames') ); } ), diff --git a/tests/Console/Command/fixtures/GenerateDocumentationCommandTest/testExecution_expectedExport.md b/tests/Console/Command/fixtures/GenerateDocumentationCommandTest/testExecution_expectedExport.md index 32da5878..20d8a262 100644 --- a/tests/Console/Command/fixtures/GenerateDocumentationCommandTest/testExecution_expectedExport.md +++ b/tests/Console/Command/fixtures/GenerateDocumentationCommandTest/testExecution_expectedExport.md @@ -1,116 +1,3 @@ -`_complete` ------------ - -Internal command to provide shell completion suggestions - -### Usage - -* `_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]` - -Internal command to provide shell completion suggestions - -### Options - -#### `--shell|-s` - -The shell type ("bash") - -* Accept value: yes -* Is value required: yes -* Is multiple: no -* Is negatable: no -* Default: `NULL` - -#### `--input|-i` - -An array of input tokens (e.g. COMP_WORDS or argv) - -* Accept value: yes -* Is value required: yes -* Is multiple: yes -* Is negatable: no -* Default: `array ()` - -#### `--current|-c` - -The index of the "input" array that the cursor is in (e.g. COMP_CWORD) - -* Accept value: yes -* Is value required: yes -* Is multiple: no -* Is negatable: no -* Default: `NULL` - -#### `--symfony|-S` - -The version of the completion script - -* Accept value: yes -* Is value required: yes -* Is multiple: no -* Is negatable: no -* Default: `NULL` - -#### `--help|-h` - -Display help for the given command. When no command is given display help for the list command - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: no -* Default: `false` - -#### `--quiet|-q` - -Do not output any message - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: no -* Default: `false` - -#### `--verbose|-v|-vv|-vvv` - -Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: no -* Default: `false` - -#### `--version|-V` - -Display this application version - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: no -* Default: `false` - -#### `--ansi|--no-ansi` - -Force (or disable --no-ansi) ANSI output - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: yes -* Default: `NULL` - -#### `--no-interaction|-n` - -Do not ask any interactive question - -* Accept value: no -* Is value required: no -* Is multiple: no -* Is negatable: no -* Default: `false` - `draw:console:generate-documentation` -------------------------------------