Altax\Command\Builtin\TasksCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $container = $this->getApplication()->getContainer();
        $tasks = $container->get('tasks');
        $format = $input->getOption('format');
        if ('txt' === $format) {
            if ($tasks) {
                $table = $this->getHelperSet()->get('table');
                $table->setHeaders(array('name', 'description', 'hidden'));
                foreach ($tasks as $task) {
                    $command = $task->createCommandInstance();
                    $table->addRow(array($task->getName(), $command->getDescription(), $task->isHidden() ? 'X' : ''));
                }
                $table->render($output);
            } else {
                $output->writeln('No tasks defined.');
            }
        } else {
            if ('json' === $format) {
                $data = array();
                if ($tasks) {
                    foreach ($tasks as $task) {
                        $command = $task->createCommandInstance();
                        $data[$task->getName()] = array('description' => $command->getDescription(), 'hidden' => $task->isHidden());
                    }
                }
                $output->writeln(json_encode($data));
            } else {
                throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
            }
        }
    }