Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --quiet option. Closes #211 #228

Merged
merged 4 commits into from Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 32 additions & 12 deletions src/main/php/PDepend/TextUI/Command.php
Expand Up @@ -210,6 +210,14 @@ public function run()
unset($options['--optimization']);
}

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

if (isset($options['--notify-me'])) {
$this->runner->addProcessListener(
new \PDepend\DbusUI\ResultPrinter()
Expand All @@ -225,8 +233,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,17 +257,9 @@ public function run()
}
echo PHP_EOL;
}

$duration = time() - $startTime;
$hours = intval($duration / 3600);
$minutes = intval(($duration - $hours * 3600) / 60);
$seconds = $duration % 60;
echo PHP_EOL, 'Time: ', sprintf('%d:%02d:%02d', $hours, $minutes, $seconds);
if (function_exists('memory_get_peak_usage')) {
$memory = (memory_get_peak_usage(true) / (1024 * 1024));
printf('; Memory: %4.2fMb', $memory);
if ($runSilent === false) {
$this->printStatistics($startTime);
}
echo PHP_EOL;

return $result;
} catch (\RuntimeException $e) {
Expand Down Expand Up @@ -481,6 +483,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 Expand Up @@ -623,4 +626,21 @@ public static function main()
$command = new Command();
return $command->run();
}

/**
* @param $startTime
*/
private function printStatistics($startTime)
{
$duration = time() - $startTime;
$hours = intval($duration / 3600);
$minutes = intval(($duration - $hours * 3600) / 60);
$seconds = $duration % 60;
echo PHP_EOL, 'Time: ', sprintf('%d:%02d:%02d', $hours, $minutes, $seconds);
if (function_exists('memory_get_peak_usage')) {
$memory = (memory_get_peak_usage(true) / (1024 * 1024));
printf('; Memory: %4.2fMb', $memory);
}
echo PHP_EOL;
}
}
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