Skip to content

Commit

Permalink
Add a --supress-messages global option to turn off all task io messag…
Browse files Browse the repository at this point in the history
…es. (#396)
  • Loading branch information
greg-1-anderson authored and DavertMik committed Aug 3, 2016
1 parent b7a7930 commit ef259b6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function __construct($name, $version)
->addOption(
new InputOption('--progress-delay', null, InputOption::VALUE_REQUIRED, 'Number of seconds before progress bar is displayed in long-running task collections. Default: 2s.')
);
$this->getDefinition()
->addOption(
new InputOption('--supress-messages', null, InputOption::VALUE_NONE, 'Supress all Robo TaskIO messages.')
);
}

public function addInitRoboFileCommand($roboFile, $roboClass)
Expand Down
2 changes: 0 additions & 2 deletions src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use Robo\Result;
use Psr\Log\LogLevel;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Contract\TaskInterface;
use Robo\Container\SimpleServiceProvider;
use Robo\Task\StackBasedTask;
Expand Down
4 changes: 4 additions & 0 deletions src/Common/TaskIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Robo\Robo;
use Robo\TaskInfo;
use Consolidation\Log\ConsoleLogLevel;
use Robo\Common\ConfigAwareTrait;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -106,6 +107,9 @@ protected function printTaskDebug($text, $context = null)

protected function printTaskOutput($level, $text, $context)
{
if ($this->getConfig()->isSupressed()) {
return;
}
// Hide the progress indicator, if it is visible.
$inProgress = $this->hideTaskProgress();
$this->logger()->log($level, $text, $this->getTaskContext($context));
Expand Down
27 changes: 25 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class Config
{
const SIMULATE = 'simulate';
const PROGRESS_BAR_AUTO_DISPLAY_INTERVAL = 'progress-delay';
const SIMULATE = 'simulate';
const SUPRESS_MESSAGES = 'supress-messages';

protected $config = [];

Expand All @@ -16,14 +17,16 @@ public function get($key, $default = null)
public function set($key, $value)
{
$this->config[$key] = $value;
return $this;
}

public function setGlobalOptions($input)
{
$globalOptions =
[
self::SIMULATE => false,
self::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL => 2,
self::SIMULATE => false,
self::SUPRESS_MESSAGES => false,
];

foreach ($globalOptions as $option => $default) {
Expand All @@ -40,4 +43,24 @@ public function isSimulated()
{
return $this->get(self::SIMULATE);
}

public function setSimulated($simulated = true)
{
return $this->set(self::SIMULATE, $simulated);
}

public function isSupressed()
{
return $this->get(self::SUPRESS_MESSAGES);
}

public function setSupressed($supressed = true)
{
return $this->set(self::SUPRESS_MESSAGES, $supressed);
}

public function setProgressBarAutoDisplayInterval($interval)
{
return $this->set(self::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL, $interval);
}
}
1 change: 0 additions & 1 deletion src/GlobalOptionsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Robo\Collection\CollectionBuilder;
use Robo\Contract\ConfigAwareInterface;
use Robo\Common\ConfigAwareTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/Task/BaseTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Psr\Log\LoggerAwareInterface;

// TODO: Ensure that ConfigAwareInterface is only used for global options; then, add it only to tasks that need it.
abstract class BaseTask implements TaskInterface, LoggerAwareInterface, ProgressIndicatorAwareInterface, ConfigAwareInterface, InflectionInterface
abstract class BaseTask implements TaskInterface, LoggerAwareInterface, ConfigAwareInterface, ProgressIndicatorAwareInterface, InflectionInterface
{
use TaskIO; // uses LoggerAwareTrait
use TaskIO; // uses LoggerAwareTrait and ConfigAwareTrait
use ProgressIndicatorAwareTrait;
use ConfigAwareTrait;
use InflectionTrait;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Task/SvnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function _before()
'executeCommand' => new \AspectMock\Proxy\Anything(),
'getOutput' => $nullOutput,
'logger' => $this->container->get('logger'),
'getConfig' => $this->container->get('config'),
'progressIndicator' => $progressIndicator,
]);
}
Expand Down

0 comments on commit ef259b6

Please sign in to comment.