本文整理汇总了PHP中Symfony\Component\Console\Command\Command::setDescription方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::setDescription方法的具体用法?PHP Command::setDescription怎么用?PHP Command::setDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Command\Command
的用法示例。
在下文中一共展示了Command::setDescription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDescription
/**
* @param string $desc
* @return static
*/
public function setDescription($desc)
{
if ($this instanceof IMightLoseData) {
$desc .= ' <comment>(loses current data)</comment>';
}
return parent::setDescription($desc);
}
示例2: __construct
/**
* Set up the command settings
*
* @return void
* @author Dan Cox
*/
public function __construct()
{
// Set the name and description
parent::__construct($this->name);
parent::setDescription($this->description);
// Run the setup method for everything else
$this->setup();
}
示例3: generateCommand
/**
* creates a Command based on an Api Method.
*
* @param string $name
* @param \ReflectionMethod $method
* @param string $token
*
* @return Command
*/
private function generateCommand($name, \ReflectionMethod $method, $token = null)
{
$methodName = $this->transformer->transform($method->getName());
$command = new Command(strtolower($name . ':' . $methodName));
$docBlock = DocBlockFactory::createInstance()->create($method->getDocComment());
$command->setDefinition($this->buildDefinition($method, $token));
$command->setDescription($docBlock->getSummary());
$command->setCode($this->createCode($name, $method));
return $command;
}
示例4: addInitRoboFileCommand
public function addInitRoboFileCommand($roboFile, $roboClass)
{
$createRoboFile = new Command('init');
$createRoboFile->setDescription("Intitalizes basic RoboFile in current dir");
$createRoboFile->setCode(function () use($roboClass, $roboFile) {
$output = Config::get('output');
$output->writeln("<comment> ~~~ Welcome to Robo! ~~~~ </comment>");
$output->writeln("<comment> " . $roboFile . " will be created in current dir </comment>");
file_put_contents($roboFile, '<?php' . "\n/**" . "\n * This is project's console commands configuration for Robo task runner." . "\n *" . "\n * @see http://robo.li/" . "\n */" . "\nclass " . $roboClass . " extends \\Robo\\Tasks\n{\n // define public methods as commands\n}");
$output->writeln("<comment> Edit RoboFile.php to add your commands! </comment>");
});
$this->add($createRoboFile);
}
示例5: buildCommand
/**
* Build a Symfony Console commands.
*
* @param \Yosymfony\Spress\Plugin\CommandPluginInterface $commandPlugin
*
* @return \Symfony\Component\Console\Command\Command Symfony Console command.
*/
protected function buildCommand(CommandPluginInterface $commandPlugin)
{
$definition = $commandPlugin->getCommandDefinition();
$argumentsAndOptions = [];
$consoleComand = new Command($definition->getName());
$consoleComand->setDescription($definition->getDescription());
$consoleComand->setHelp($definition->getHelp());
foreach ($definition->getArguments() as list($name, $mode, $description, $defaultValue)) {
$argumentsAndOptions[] = new InputArgument($name, $mode, $description, $defaultValue);
}
foreach ($definition->getOptions() as list($name, $shortcut, $mode, $description, $defaultValue)) {
$argumentsAndOptions[] = new InputOption($name, $shortcut, $mode, $description, $defaultValue);
}
$consoleComand->setDefinition($argumentsAndOptions);
$consoleComand->setCode(function (InputInterface $input, OutputInterface $output) use($commandPlugin) {
$io = new ConsoleIO($input, $output);
$arguments = $input->getArguments();
$options = $input->getOptions();
$commandPlugin->executeCommand($io, $arguments, $options);
});
return $consoleComand;
}
示例6: setDescription
/**
* {@inheritdoc}
*/
public function setDescription($description)
{
$this->decoratedCommand->setDescription($description);
return $this;
}
示例7: createCommand
/**
* @param $className
* @param TaskInfo $taskInfo
* @return Command
*/
protected function createCommand($className, TaskInfo $taskInfo)
{
if ($className === strtolower(Tg::TGCLASS)) {
$name = $taskInfo->getName();
} else {
$camel = preg_replace("/:/", '-', $taskInfo->getName());
$name = $className . ':' . $camel;
}
$task = new Command($name);
$task->setDescription($taskInfo->getDescription());
$task->setHelp($taskInfo->getHelp());
$args = $taskInfo->getArguments();
foreach ($args as $name => $val) {
$description = $taskInfo->getArgumentDescription($name);
if ($val === TaskInfo::PARAM_IS_REQUIRED) {
$task->addArgument($name, InputArgument::REQUIRED, $description);
} elseif (is_array($val)) {
$task->addArgument($name, InputArgument::IS_ARRAY, $description, $val);
} else {
$task->addArgument($name, InputArgument::OPTIONAL, $description, $val);
}
}
$opts = $taskInfo->getOptions();
foreach ($opts as $name => $val) {
$description = $taskInfo->getOptionDescription($name);
$fullName = $name;
$shortcut = '';
if (strpos($name, '|')) {
list($fullName, $shortcut) = explode('|', $name, 2);
}
if (is_bool($val)) {
$task->addOption($fullName, $shortcut, InputOption::VALUE_NONE, $description);
} else {
$task->addOption($fullName, $shortcut, InputOption::VALUE_OPTIONAL, $description, $val);
}
}
return $task;
}
示例8: setDescription
public function setDescription($description)
{
return $this->innerCommand->setDescription($description);
}
示例9: createCommand
public function createCommand(TaskInfo $taskInfo)
{
$task = new Command($taskInfo->getName());
$task->setDescription($taskInfo->getDescription());
$task->setHelp($taskInfo->getHelp());
$args = $taskInfo->getArguments();
foreach ($args as $name => $val) {
$description = $taskInfo->getArgumentDescription($name);
if ($val === TaskInfo::PARAM_IS_REQUIRED) {
$task->addArgument($name, InputArgument::REQUIRED, $description);
} elseif (is_array($val)) {
$task->addArgument($name, InputArgument::IS_ARRAY, $description, $val);
} else {
$task->addArgument($name, InputArgument::OPTIONAL, $description, $val);
}
}
$opts = $taskInfo->getOptions();
foreach ($opts as $name => $val) {
$description = $taskInfo->getOptionDescription($name);
$fullname = $name;
$shortcut = '';
if (strpos($name, '|')) {
list($fullname, $shortcut) = explode('|', $name, 2);
}
if (is_bool($val)) {
$task->addOption($fullname, $shortcut, InputOption::VALUE_NONE, $description);
} else {
$task->addOption($fullname, $shortcut, InputOption::VALUE_OPTIONAL, $description, $val);
}
}
return $task;
}
示例10: configure
/**
* Configures a console command by setting name, description, arguments, etc.
*
* @param Command $command
*/
public static function configure(Command $command)
{
$command->setName('config:status');
$command->setAliases(['status']);
$command->setDescription('Shows the current migration status.');
}
示例11: getDescription
/**
* Get the description
*
* @return string
*/
public function getDescription()
{
$description = parent::getDescription();
if ($description === null) {
$descriptor = new Descriptor();
$description = (string) $descriptor->describeTask($this->getJob());
parent::setDescription($description);
}
return $description;
}
示例12: addCommand
/**
* Registers a command.
*
* @param string $name Name of the command.
* @param string $commandClass Class name of the command.
*/
public function addCommand($name, $commandClass)
{
// must extend AbstractCommand
$abstractCommandClass = AbstractCommand::class;
if (!Debugger::isExtending($commandClass, $abstractCommandClass)) {
throw new InvalidCommandException('Command "' . $commandClass . '" must extend "' . $abstractCommandClass . '".');
}
// name cannot be empty
$name = trim($name);
if (empty($name)) {
throw new InvalidArgumentException('Command name cannot be empty for "' . $commandClass . '"!');
}
// configure the command
$console = $this;
$consoleCommand = new ConsoleCommand($name);
$consoleCommand->setDescription($commandClass::getDescription());
$consoleCommand->setHelp($commandClass::getHelp());
$consoleCommand->setCode(function (InputInterface $input, OutputInterface $output) use($console, $name) {
$console->exec($name, $input, $output);
});
// read some meta info about the command
$commandReflection = new \ReflectionClass($commandClass);
$arguments = array();
$argumentsDescriptions = $commandClass::getArguments();
try {
$methodReflection = $commandReflection->getMethod('execute');
if (!$methodReflection->isPublic() || $methodReflection->isStatic()) {
throw new InvalidCommandException('The "execute()" method for ommand "' . $commandClass . '" must be public and non-static.');
}
// get the execute() method's arguments so we can translate them to CLI arguments
$parametersReflection = $methodReflection->getParameters();
foreach ($parametersReflection as $param) {
$optional = $param->isDefaultValueAvailable();
$paramName = $param->getName();
$arguments[] = array('name' => $paramName, 'optional' => $optional, 'default' => $optional ? $param->getDefaultValue() : null, 'description' => isset($argumentsDescriptions[$paramName]) ? $argumentsDescriptions[$paramName] : '');
}
} catch (\ReflectionException $e) {
throw new InvalidCommandException('Command "' . $commandClass . '" must implement public function "execute()"!');
}
foreach ($arguments as $argument) {
$consoleCommand->addArgument($argument['name'], $argument['optional'] ? InputArgument::OPTIONAL : InputArgument::REQUIRED, $argument['description'], $argument['default']);
}
// also register command's options
$options = $commandClass::getOptions();
foreach ($options as $option => $optionInfo) {
$value = isset($optionInfo['required']) && $optionInfo['required'] ? InputOption::VALUE_REQUIRED : (!isset($optionInfo['default']) || empty($optionInfo['default']) || $optionInfo['default'] === null ? InputOption::VALUE_NONE : InputOption::VALUE_OPTIONAL);
$consoleCommand->addOption($option, isset($optionInfo['shortcut']) ? $optionInfo['shortcut'] : null, $value, isset($optionInfo['description']) ? $optionInfo['description'] : '', $value === InputOption::VALUE_REQUIRED || $value === InputOption::VALUE_NONE ? null : (isset($optionInfo['default']) ? $optionInfo['default'] : null));
}
// register the command
$this->commands[$name] = array('name' => $name, 'class' => $commandClass, 'command' => $consoleCommand, 'arguments' => $arguments, 'options' => $options);
$this->consoleApplication->add($consoleCommand);
}
示例13: createCommand
protected function createCommand($taskName)
{
$taskInfo = new TaskInfo(self::ROBOCLASS, $taskName);
$task = new Command($taskInfo->getName());
$task->setDescription($taskInfo->getDescription());
$args = $taskInfo->getArguments();
foreach ($args as $name => $val) {
if ($val === TaskInfo::PARAM_IS_REQUIRED) {
$task->addArgument($name, InputArgument::REQUIRED);
} elseif (is_array($val)) {
$task->addArgument($name, InputArgument::IS_ARRAY, '', $val);
} else {
$task->addArgument($name, InputArgument::OPTIONAL, '', $val);
}
}
$opts = $taskInfo->getOptions();
foreach ($opts as $name => $val) {
if (empty($val)) {
$task->addOption($name, '', InputOption::VALUE_NONE, '');
} else {
$task->addOption($name, '', InputOption::VALUE_OPTIONAL, '', $val);
}
}
return $task;
}
示例14: Command
$output->writeLn(sprintf('Parsed city <info>%s</info> in country <info>%s</info> in zone <info>%s</info>', $data['FIELD2'], $data['FIELD9'], $data['FIELD18']));
} else {
$output->write('.');
}
});
});
# parse data and load into table
$parser->parse(__DIR__ . '/cities15000.csv', $parser_options);
$output->writeLn('Finished <info>parsing names</info> into database');
});
//---------------------------------------------------------------------
// Parse Countries csv
//
//--------------------------------------------------------------------
$parse_countries = new Command('countries');
$parse_countries->setDescription('Parse Csv of countries into the local sqlite db');
$parse_countries->setCode(function (InputInterface $input, ConsoleOutputInterface $output) use($project) {
$output->writeLn('Starting Parse of Country this may <info>take a while</info>');
# create a csv parser
$parser = $project['parser'];
$parser_options = $project['parser_options'];
$parser_options->setParser('csv');
$parser_options->setHasHeaderRow(false);
$parser_options->setFieldSeperator(59);
$parser_options->setSkipRows(0);
# register for the generate event
$event = $project['event_dispatcher'];
$connection = $project['faker_database'];
$event->addListener('row_parsed', function (Faker\Parser\Event\RowParsed $event) use($connection, $output, $input) {
/* Example of data from names file
Array
示例15: configure
/**
* @inheritdoc
*/
public static function configure(Command $command)
{
$command->setName('config:init');
$command->setAliases(['init']);
$command->setDescription('Initialises Baleen by creating a config file in the current directory.');
}