Skip to content

Commit

Permalink
[Console] Filter in/out support
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Nov 13, 2023
1 parent 718723f commit 31c6e56
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 147 deletions.
3 changes: 2 additions & 1 deletion config/packages/draw_framework_extra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ draw_framework_extra:

console:
documentation:
ignored_commands: [ 'completion', 'help', 'list' ]
filter: 'in'
command_names: [ 'draw:console:generate-documentation' ]

doctrine_extra: ~

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Draw\Bundle\FrameworkExtraBundle\Console\EventListener;

use Draw\Component\Console\Event\GenerateDocumentationEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

class DocumentationFilterCommandEventListener
{
public const FILTER_OUT = 'out';
public const FILTER_IN = 'in';

public function __construct(private array $commandNames, private string $filter = self::FILTER_OUT)
{
}

#[AsEventListener]
public function onGenerateDocumentationEvent(GenerateDocumentationEvent $event): void
{
$match = \in_array($event->getCommand()->getName(), $this->commandNames);

if ($match && self::FILTER_OUT === $this->filter) {
$event->ignore();

return;
}

if (!$match && self::FILTER_IN === $this->filter) {
$event->ignore();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +35,8 @@ public function getDefaultConfiguration(): array
return [
'ignore_disabled_command' => false,
'documentation' => [
'ignored_commands' => [],
'filter' => 'in',
'command_names' => [],
],
];
}
Expand Down Expand Up @@ -92,7 +93,8 @@ public static function provideTestLoad(): iterable
[
'ignore_disabled_command' => true,
'documentation' => [
'ignored_commands' => [
'filter' => 'out',
'command_names' => [
'help',
],
],
Expand Down Expand Up @@ -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')
);
}
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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`
-------------------------------------

Expand Down

0 comments on commit 31c6e56

Please sign in to comment.