Skip to content

Commit

Permalink
Add --quiet option to suppress STDOUT output
Browse files Browse the repository at this point in the history
we want to suppress any output that is not an error when running
pdepend. For this I am adding a new option --quiet to the TextUI
Command. Setting this flag will put pdepend into silent mode, meaning it
will use the NulLResultPrinter instead of the regular ResultPrinter and
it will not output version, workarounds and runtime statistics. It will
output any errors though.

Closes #211
  • Loading branch information
gooh committed Oct 17, 2015
1 parent 8a47ef3 commit 9a710f7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/main/php/PDepend/TextUI/Command.php
Expand Up @@ -210,6 +210,16 @@ public function run()
unset($options['--optimization']);
}

if (isset($options['--quiet'])) {
$runSilent = true;
$processListener = new \PDepend\TextUI\NullResultPrinter();
unset($options['--quiet']);
} else {
$runSilent = false;
$processListener = new \PDepend\TextUI\ResultPrinter();
}
$this->runner->addProcessListener($processListener);

if (isset($options['--notify-me'])) {
$this->runner->addProcessListener(
new \PDepend\DbusUI\ResultPrinter()
Expand All @@ -225,8 +235,10 @@ public function run()

try {
// Output current pdepend version and author
$this->printVersion();
$this->printWorkarounds();
if ($runSilent === false) {
$this->printVersion();
$this->printWorkarounds();
}

$startTime = time();

Expand All @@ -247,8 +259,9 @@ public function run()
}
echo PHP_EOL;
}

$this->printStatistics($startTime);
if ($runSilent === false) {
$this->printStatistics($startTime);
}

return $result;
} catch (\RuntimeException $e) {
Expand Down Expand Up @@ -472,6 +485,7 @@ protected function printHelp()
);
echo PHP_EOL;

$this->printOption('--quiet', 'Prints errors only.', $length);
$this->printOption('--debug', 'Prints debugging information.', $length);
$this->printOption('--help', 'Print this help text.', $length);
$this->printOption('--version', 'Print the current version.', $length);
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/services.xml
Expand Up @@ -8,10 +8,6 @@
<service id="pdepend.textui.runner" class="PDepend\TextUI\Runner">
<argument type="service" id="pdepend.report_generator_factory" />
<argument type="service" id="pdepend.engine" />

<call method="addProcessListener">
<argument type="service" id="pdepend.textui.result_printer" />
</call>
</service>

<service id="pdepend.util.cache_factory" class="PDepend\Util\Cache\CacheFactory">
Expand Down
17 changes: 17 additions & 0 deletions src/test/php/PDepend/TextUI/CommandTest.php
Expand Up @@ -543,6 +543,22 @@ public function testCommandFailsIfAnInvalidConfigFileWasSpecified()
);
}

public function testQuietModeWillSuppressVersionAndWorkaroundsAndStatistics()
{
$argv = array(
'--quiet',
'--coverage-report=' . dirname(__FILE__) . '/_files/clover.xml',
'--dummy-logger=' . $this->createRunResourceURI(),
'--configuration=' . __DIR__ . '/../../../resources/pdepend.xml.dist',
__FILE__,
);

list($exitCode, $actual) = $this->executeCommand($argv);

$this->assertEquals(Runner::SUCCESS_EXIT, $exitCode);
$this->assertEmpty('', $actual);
}

/**
* Tests the help output with an optional prolog text.
*
Expand All @@ -565,6 +581,7 @@ protected function assertHelpOutput($actual, $prologText = '')
$this->assertRegExp('( --help[ ]+Print\s+this\s+help\s+text\.)', $actual);
$this->assertRegExp('( --version[ ]+Print\s+the\s+current\s+version\.)', $actual);
$this->assertRegExp('( -d key\[=value\][ ]+Sets\s+a\s+php.ini\s+value\.)', $actual);
$this->assertRegExp('( --quiet[ ]+Prints\s+errors\s+only\.)', $actual);
}

/**
Expand Down

0 comments on commit 9a710f7

Please sign in to comment.