我在运行Symfony2 CLI命令后尝试打印彩色表,这个命令在单独运行时工作正常:
CLI命令:
php app/console phing:report inanzzz
输出:
问题:
当我在Phing中运行相同的CLI命令时,表格颜色被覆盖,如下所示。有谁知道它的解决方案?
CLI命令:
bin/phing build-report
输出:
相同CLI命令的Phing条目:
<target name="build-report">
<echo msg="Generating final build report ..." />
<exec logoutput="true" checkreturn="true" command="php app/console phing:report inanzzz" dir="./" />
</target>
CLI命令类:
namespace Site\FrontendBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;
class PhingCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('phing:report')
->addArgument('path', InputArgument::IS_ARRAY, 'Path argument is missing!'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument('path');
$message[] = array(
'<fg=green>Behat</fg=green>',
'<fg=green>behat-2014.html</fg=green>',
'<fg=green>0</fg=green>',
'<fg=green>Success</fg=green>'
);
$message[] = array(
'<fg=green>Copy Paste Detector</fg=green>',
'<fg=green>phpcpd-2014.html</fg=green>',
'<fg=green>0</fg=green>',
'<fg=green>Success</fg=green>'
);
$message[] = array(
'<fg=red>Codesniffer</fg=red>',
'<fg=red>phpcs-2014.html</fg=red>',
'<fg=red>4</fg=red>',
'<fg=red;options=blink>Fail</fg=red;options=blink>'
);
$message[] = array(
'<fg=yellow>Mess Detector</fg=yellow>',
'<fg=yellow>phpmd-2014.html</fg=yellow>',
'<fg=yellow>14</fg=yellow>',
'<fg=yellow>Warning</fg=yellow>'
);
$table = new Table($output);
$table
->setHeaders(
array(
'<fg=white;options=bold>TEST</fg=white;options=bold>',
'<fg=white;options=bold>LOG FILE</fg=white;options=bold>',
'<fg=white;options=bold>ERROR COUNT</fg=white;options=bold>',
'<fg=white;options=bold>STATUS</fg=white;options=bold>'
)
)
->setRows($message)
;
$table->render();
}
}
答案 0 :(得分:1)
尝试将passthru="true"
属性添加到<exec/>
元素:
<target name="build-report">
<echo msg="Generating final build report ..." />
<exec passthru="true" logoutput="true" checkreturn="true" command="php app/console phing:report inanzzz" dir="./"/>
</target>