问题
I'm trying to print a coloured table after running a Symfony2 CLI command which works fine when running on its own like this:
CLI Command:
php app/console phing:report inanzzz
Output:
PROBLEM:
When I run same CLI command within Phing, table colour is being overridden as seen below. Anyone knows a solution to it?
CLI Command:
bin/phing build-report
Output:
Phing entry for same CLI command:
<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 Command Class:
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();
}
}
回答1:
Try adding passthru="true"
attribute to your <exec/>
element:
<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>
来源:https://stackoverflow.com/questions/26176828/phing-overrides-symfony2-cli-table-output-colours