Параметр help атрибута AsCommand
Параметр help атрибута AsCommand задаёт
дополнительный текст справки для консольной команды.
Он отображается в секции Help при выполнении
команды с опцией --help. Значение передаётся
строкой и может содержать несколько предложений.
В отличие от параметра description, который
показывается в общем списке команд, параметр help
предназначен для подробного пояснения работы команды,
её аргументов и опций.
Синтаксис
#[AsCommand(
name: name,
description: description,
help: help
)]
Пример
Давайте создадим команду с подробным текстом справки:
<?php
namespace AppCommand;
use SymfonyComponentConsoleAttributeAsCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
#[AsCommand(
name: 'app:article',
description: 'Creates an article',
help: 'This command creates a new article. Use it to add records to the database.'
)]
class ArticleCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('article created');
return Command::SUCCESS;
}
}
?>
Результат выполнения команды php bin/console app:article --help:
Description:
Creates an article
Usage:
app:article
Help:
This command creates a new article. Use it to add records to the database.
Пример
Давайте добавим многострочный текст справки с переносами:
<?php
namespace AppCommand;
use SymfonyComponentConsoleAttributeAsCommand;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
#[AsCommand(
name: 'app:user',
description: 'Manages users',
help: 'This command manages users.
You can create, update and delete users.
Use the options below to control the behavior.'
)]
class UserCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('user processed');
return Command::SUCCESS;
}
}
?>
Результат выполнения команды php bin/console app:user --help:
Description:
Manages users
Usage:
app:user
Help:
This command manages users.
You can create, update and delete users.
Use the options below to control the behavior.
Смотрите также
-
атрибут
AsCommand,
который регистрирует консольную команду -
параметр
name,
который задаёт имя команды -
параметр
description,
который задаёт краткое описание команды -
параметр
hidden,
который скрывает команду из списка