Skip to content

[Console] enable describing commands in ways that make the list command lazy #39851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ServerLogCommand extends Command
private $handler;

protected static $defaultName = 'server:log';
protected static $defaultDescription = 'Starts a log server that displays logs in real time';

public function isEnabled()
{
Expand All @@ -60,7 +61,7 @@ protected function configure()
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The line format', ConsoleFormatter::SIMPLE_FORMAT)
->addOption('date-format', null, InputOption::VALUE_REQUIRED, 'The date format', ConsoleFormatter::SIMPLE_DATE)
->addOption('filter', null, InputOption::VALUE_REQUIRED, 'An expression to filter log. Example: "level > 200 or channel in [\'app\', \'doctrine\']"')
->setDescription('Starts a log server that displays logs in real time')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
<info>%command.name%</info> starts a log server to display in real time the log
messages generated by your application:
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class DebugCommand extends Command
{
protected static $defaultName = 'debug:twig';
protected static $defaultDescription = 'Shows a list of twig functions, filters, globals and tests';

private $twig;
private $projectDir;
Expand Down Expand Up @@ -60,7 +61,7 @@ protected function configure()
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'Show details for all entries matching this filter'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (text or json)', 'text'),
])
->setDescription('Shows a list of twig functions, filters, globals and tests')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command outputs a list of twig functions,
filters, globals and tests.
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class LintCommand extends Command
{
protected static $defaultName = 'lint:twig';
protected static $defaultDescription = 'Lints a template and outputs encountered errors';

private $twig;

Expand All @@ -48,7 +49,7 @@ public function __construct(Environment $twig)
protected function configure()
{
$this
->setDescription('Lints a template and outputs encountered errors')
->setDescription(self::$defaultDescription)
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Bundle/DebugBundle/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Monolog\Formatter\FormatterInterface;
use Symfony\Bridge\Monolog\Command\ServerLogCommand;
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
use Symfony\Bridge\Twig\Extension\DumpExtension;
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\HttpKernel\EventListener\DumpListener;
Expand Down Expand Up @@ -127,9 +129,12 @@
'html' => inline_service(HtmlDescriptor::class)->args([service('var_dumper.html_dumper')]),
],
])
->tag('console.command', ['command' => 'server:dump'])
->tag('console.command')

->set('monolog.command.server_log', ServerLogCommand::class)
->tag('console.command', ['command' => 'server:log'])
;

if (class_exists(ConsoleFormatter::class) && interface_exists(FormatterInterface::class)) {
$container->services()->get('monolog.command.server_log')->tag('console.command');
}
};
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
class AboutCommand extends Command
{
protected static $defaultName = 'about';
protected static $defaultDescription = 'Displays information about the current project';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setDescription('Displays information about the current project')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOT'
The <info>%command.name%</info> command displays information about the current Symfony project.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AssetsInstallCommand extends Command
public const METHOD_RELATIVE_SYMLINK = 'relative symlink';

protected static $defaultName = 'assets:install';
protected static $defaultDescription = 'Installs bundles web assets under a public directory';

private $filesystem;
private $projectDir;
Expand All @@ -64,7 +65,7 @@ protected function configure()
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
->addOption('no-cleanup', null, InputOption::VALUE_NONE, 'Do not remove the assets of the bundles that no longer exist')
->setDescription('Installs bundles web assets under a public directory')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOT'
The <info>%command.name%</info> command installs bundle assets into a given
directory (e.g. the <comment>public</comment> directory).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class CacheClearCommand extends Command
{
protected static $defaultName = 'cache:clear';
protected static $defaultDescription = 'Clears the cache';

private $cacheClearer;
private $filesystem;
Expand All @@ -58,7 +59,7 @@ protected function configure()
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
])
->setDescription('Clears the cache')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command clears the application cache for a given environment
and debug mode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
final class CachePoolClearCommand extends Command
{
protected static $defaultName = 'cache:pool:clear';
protected static $defaultDescription = 'Clears cache pools';

private $poolClearer;

Expand All @@ -47,7 +48,7 @@ protected function configure()
->setDefinition([
new InputArgument('pools', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of cache pools or cache pool clearers'),
])
->setDescription('Clears cache pools')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command clears the given cache pools or cache pool clearers.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
final class CachePoolDeleteCommand extends Command
{
protected static $defaultName = 'cache:pool:delete';
protected static $defaultDescription = 'Deletes an item from a cache pool';

private $poolClearer;

Expand All @@ -46,7 +47,7 @@ protected function configure()
new InputArgument('pool', InputArgument::REQUIRED, 'The cache pool from which to delete an item'),
new InputArgument('key', InputArgument::REQUIRED, 'The cache key to delete from the pool'),
])
->setDescription('Deletes an item from a cache pool')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> deletes an item from a given cache pool.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
final class CachePoolListCommand extends Command
{
protected static $defaultName = 'cache:pool:list';
protected static $defaultDescription = 'List available cache pools';

private $poolNames;

Expand All @@ -40,7 +41,7 @@ public function __construct(array $poolNames)
protected function configure()
{
$this
->setDescription('List available cache pools')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command lists all available cache pools.
EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
final class CachePoolPruneCommand extends Command
{
protected static $defaultName = 'cache:pool:prune';
protected static $defaultDescription = 'Prunes cache pools';

private $pools;

Expand All @@ -44,7 +45,7 @@ public function __construct(iterable $pools)
protected function configure()
{
$this
->setDescription('Prunes cache pools')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command deletes all expired items from all pruneable pools.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class CacheWarmupCommand extends Command
{
protected static $defaultName = 'cache:warmup';
protected static $defaultDescription = 'Warms up an empty cache';

private $cacheWarmer;

Expand All @@ -48,7 +49,7 @@ protected function configure()
->setDefinition([
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
])
->setDescription('Warms up an empty cache')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command warms up the cache.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class ConfigDebugCommand extends AbstractConfigCommand
{
protected static $defaultName = 'debug:config';
protected static $defaultDescription = 'Dumps the current configuration for an extension';

/**
* {@inheritdoc}
Expand All @@ -44,7 +45,7 @@ protected function configure()
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
])
->setDescription('Dumps the current configuration for an extension')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command dumps the current configuration for an
extension/bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class ConfigDumpReferenceCommand extends AbstractConfigCommand
{
protected static $defaultName = 'config:dump-reference';
protected static $defaultDescription = 'Dumps the default configuration for an extension';

/**
* {@inheritdoc}
Expand All @@ -48,7 +49,7 @@ protected function configure()
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (yaml or xml)', 'yaml'),
])
->setDescription('Dumps the default configuration for an extension')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command dumps the default configuration for an
extension/bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ContainerDebugCommand extends Command
use BuildDebugContainerTrait;

protected static $defaultName = 'debug:container';
protected static $defaultDescription = 'Displays current services for an application';

/**
* {@inheritdoc}
Expand All @@ -57,7 +58,7 @@ protected function configure()
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'Displays deprecations generated when compiling and warming up the container'),
])
->setDescription('Displays current services for an application')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
final class ContainerLintCommand extends Command
{
protected static $defaultName = 'lint:container';
protected static $defaultDescription = 'Ensures that arguments injected into services match type declarations';

/**
* @var ContainerBuilder
Expand All @@ -42,7 +43,7 @@ final class ContainerLintCommand extends Command
protected function configure()
{
$this
->setDescription('Ensures that arguments injected into services match type declarations')
->setDescription(self::$defaultDescription)
->setHelp('This command parses service definitions and ensures that injected values match the type declarations of each services\' class.')
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class DebugAutowiringCommand extends ContainerDebugCommand
{
protected static $defaultName = 'debug:autowiring';
protected static $defaultDescription = 'Lists classes/interfaces you can use for autowiring';
private $supportsHref;
private $fileLinkFormatter;

Expand All @@ -50,7 +51,7 @@ protected function configure()
new InputArgument('search', InputArgument::OPTIONAL, 'A search filter'),
new InputOption('all', null, InputOption::VALUE_NONE, 'Show also services that are not aliased'),
])
->setDescription('Lists classes/interfaces you can use for autowiring')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command displays the classes and interfaces that
you can use as type-hints for autowiring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EventDispatcherDebugCommand extends Command
private const DEFAULT_DISPATCHER = 'event_dispatcher';

protected static $defaultName = 'debug:event-dispatcher';
protected static $defaultDescription = 'Displays configured listeners for an application';
private $dispatchers;

public function __construct(ContainerInterface $dispatchers)
Expand All @@ -54,7 +55,7 @@ protected function configure()
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
])
->setDescription('Displays configured listeners for an application')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command displays all configured listeners:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RouterDebugCommand extends Command
use BuildDebugContainerTrait;

protected static $defaultName = 'debug:router';
protected static $defaultDescription = 'Displays current routes for an application';
private $router;
private $fileLinkFormatter;

Expand All @@ -59,7 +60,7 @@ protected function configure()
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
])
->setDescription('Displays current routes for an application')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> displays the configured routes:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
class RouterMatchCommand extends Command
{
protected static $defaultName = 'router:match';
protected static $defaultDescription = 'Helps debug routes by simulating a path info match';

private $router;
private $expressionLanguageProviders;
Expand All @@ -55,7 +56,7 @@ protected function configure()
new InputOption('scheme', null, InputOption::VALUE_REQUIRED, 'Sets the URI scheme (usually http or https)'),
new InputOption('host', null, InputOption::VALUE_REQUIRED, 'Sets the URI host'),
])
->setDescription('Helps debug routes by simulating a path info match')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> shows which routes match a given request and which don't and for what reason:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
final class SecretsDecryptToLocalCommand extends Command
{
protected static $defaultName = 'secrets:decrypt-to-local';
protected static $defaultDescription = 'Decrypts all secrets and stores them in the local vault';

private $vault;
private $localVault;
Expand All @@ -42,7 +43,7 @@ public function __construct(AbstractVault $vault, AbstractVault $localVault = nu
protected function configure()
{
$this
->setDescription('Decrypts all secrets and stores them in the local vault')
->setDescription(self::$defaultDescription)
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces overriding of secrets that already exist in the local vault')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command decrypts all secrets and copies them in the local vault.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
final class SecretsEncryptFromLocalCommand extends Command
{
protected static $defaultName = 'secrets:encrypt-from-local';
protected static $defaultDescription = 'Encrypts all local secrets to the vault';

private $vault;
private $localVault;
Expand All @@ -41,7 +42,7 @@ public function __construct(AbstractVault $vault, AbstractVault $localVault = nu
protected function configure()
{
$this
->setDescription('Encrypts all local secrets to the vault')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
The <info>%command.name%</info> command encrypts all locally overridden secrets to the vault.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
final class SecretsGenerateKeysCommand extends Command
{
protected static $defaultName = 'secrets:generate-keys';
protected static $defaultDescription = 'Generates new encryption keys';

private $vault;
private $localVault;
Expand All @@ -44,7 +45,7 @@ public function __construct(AbstractVault $vault, AbstractVault $localVault = nu
protected function configure()
{
$this
->setDescription('Generates new encryption keys')
->setDescription(self::$defaultDescription)
->addOption('local', 'l', InputOption::VALUE_NONE, 'Updates the local vault.')
->addOption('rotate', 'r', InputOption::VALUE_NONE, 'Re-encrypts existing secrets with the newly generated keys.')
->setHelp(<<<'EOF'
Expand Down
Loading