Phing overrides Symfony2 CLI table output colours

旧时模样 提交于 2019-12-12 02:17:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!