Skip to content

Commit

Permalink
Merge pull request #97 from ideatosrl/symfony-style
Browse files Browse the repository at this point in the history
replaces ConsoleOutput with SymfonyStyle class
  • Loading branch information
ftassi committed Jan 31, 2017
2 parents cc19f53 + 0531678 commit 7adf18f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
30 changes: 25 additions & 5 deletions docs/writing_tasks.rst
Expand Up @@ -324,7 +324,7 @@ Writing output to the console
-----------------------------

Idephix is based on Symfony console component so you can send output to the user using the
``\Symfony\Component\Console\Output\OutputInterface``. You can get the full ``OutputInterface`` component
``\Symfony\Component\Console\Style\SymfonyStyle``. You can get the full ``SymfonyStyle`` component
through the ``\Idephix\TaskExecutor::output`` method or you can use the shortcut methods:
``\Idephix\TaskExecutor::write`` and ``\Idephix\TaskExecutor::writeln``.

Expand All @@ -343,11 +343,31 @@ Here is an example of you you can send some output to the console.
{
$context->writeln(strtoupper($what));
$context->write(strtoupper($what) . PHP_EOL);
$context->output()->write(strtoupper($what) . PHP_EOL);
$context->output()->writeln(strtoupper($what));

$output = $idx->output();

// common output elements
$output->title($what);
$output->section($what);
$output->text($what);
$output->comment($what);
$output->note($what);
$output->caution($what);
$output->listing([$what, $what, $what]);
$output->success($what);
$output->error($what);
$output->warning($what);

//table
$headers = ['Parameter', 'Value', 'Value 3'];
$rows = [
['Param1', 'Value1', 'Value 3'],
['Param2', 'Value2', 'Value 3']
];
$output->table($headers, $rows);
}

.. hint::

For more information about ``OutputInterface`` read the official
component `documentation <http://symfony.com/doc/2.8/components/console.html>`_
For more information about ``SymfonyStyle`` read the official
component `documentation <http://symfony.com/blog/new-in-symfony-2-8-console-style-guide>`_
7 changes: 4 additions & 3 deletions src/Idephix/Idephix.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Idephix\SSH\SshClient;
use Idephix\Extension\IdephixAwareInterface;
use Idephix\Task\Builtin\SelfUpdate;
Expand Down Expand Up @@ -61,8 +62,8 @@ public function __construct(

$this->sshClient = $config['ssh_client'];

$this->output = $this->outputOrDefault($output);
$this->input = $this->inputOrDefault($input);
$this->output = $this->outputOrDefault($output);

$this->addSelfUpdateCommand();
$this->addInitIdxFileCommand();
Expand Down Expand Up @@ -422,12 +423,12 @@ public function writeln($messages, $type = self::OUTPUT_NORMAL)

/**
* @param OutputInterface $output
* @return ConsoleOutput|OutputInterface
* @return SymfonyStyle|OutputInterface
*/
private function outputOrDefault(OutputInterface $output = null)
{
if (null === $output) {
$output = new ConsoleOutput();
$output = new SymfonyStyle($this->input, new ConsoleOutput());
}

return $output;
Expand Down

0 comments on commit 7adf18f

Please sign in to comment.