您可以使用冒号表示法创建新部分。
$this
->setName('newSection:greet') //<--- This line does the trick
->setDescription('Greet someone')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to greet?'
)
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
);
但是,在这种情况下,您需要运行您的命令,并将新的部分名称添加为命名空间,
> php app.php newSection:greet Avindra
.
如果您使用空格命名您的部分,如“新部分”,您需要调用您的命令,如
> php app.php "New Section:greet" Avindra
.
这就是您可以更改info
应用程序本身注释颜色的方式。
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Command\GreetCommand;
use Command\HelloCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
$application = new Application();
$application->add(new GreetCommand());
$application->add(new HelloCommand());
//Create a new OutputFormatter
$formatter = new OutputFormatter();
//Change info annotation color by blue
$formatter->setStyle('info', new OutputFormatterStyle('blue'));
//Construct output interface with new formatter
$output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, null, $formatter);
//Run your application with your new output interface
$application->run(null, $output);
您可以在此处查看相关源代码以获取更多选项;
https://github.com/symfony/Console/blob/5f241906889f0a3e7b1854b42e7c92a0ea8516ce/Formatter/OutputFormatter.php#L51
https://github.com/symfony/Console/blob/b6b351d326e2fb2fe673a808630f938c2881a473/Formatter/OutputFormatterStyle.php#L21
希望能帮助到你。