Search code examples
symfonyphing

Phing overrides Symfony2 CLI table output colours


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:

enter image description here

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:

enter image description here

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();
    }
} 

Solution

  • 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>