Skip to content

Commit

Permalink
Added more verbosity levels
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsniper authored and Seldaek committed Apr 25, 2013
1 parent 9a3f415 commit 16cdb61
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 23 deletions.
16 changes: 14 additions & 2 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -184,10 +184,22 @@ public function doRun(InputInterface $input, OutputInterface $output)

if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
} elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
}

if (true === $input->hasParameterOption('-v')) {
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
}

if (true === $input->hasParameterOption('--verbose')) {
switch ($input->getParameterOption('--verbose', 1)) {
case 1: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); break;
case 2: $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); break;
case 3: $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); break;

default: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
}
}

if (true === $input->hasParameterOption(array('--version', '-V'))) {
$output->writeln($this->getLongVersion());

Expand Down Expand Up @@ -917,7 +929,7 @@ protected function getDefaultInputDefinition()

new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--verbose', '-v', InputOption::VALUE_OPTIONAL, 'Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)', 1),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version.'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
Expand Down
12 changes: 7 additions & 5 deletions src/Symfony/Component/Console/Output/OutputInterface.php
Expand Up @@ -22,13 +22,15 @@
*/
interface OutputInterface
{
const VERBOSITY_QUIET = 0;
const VERBOSITY_NORMAL = 1;
const VERBOSITY_VERBOSE = 2;
const VERBOSITY_QUIET = 0;
const VERBOSITY_NORMAL = 1;
const VERBOSITY_VERBOSE = 2;
const VERBOSITY_VERY_VERBOSE = 3;
const VERBOSITY_DEBUG = 4;

const OUTPUT_NORMAL = 0;
const OUTPUT_RAW = 1;
const OUTPUT_PLAIN = 2;
const OUTPUT_RAW = 1;
const OUTPUT_PLAIN = 2;

/**
* Writes a message to the output.
Expand Down
16 changes: 14 additions & 2 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -406,8 +406,8 @@ public function testAsXml()
$application = new Application();
$application->add(new \FooCommand);
$this->ensureStaticCommandHelp($application);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml(1) returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml(2) returns an XML representation of the application');
}

public function testRenderException()
Expand Down Expand Up @@ -502,6 +502,18 @@ public function testRun()
$tester->run(array('command' => 'list', '--verbose' => true));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');

$tester->run(array('command' => 'list', '--verbose' => 1));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');

$tester->run(array('command' => 'list', '--verbose' => 2));
$this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed');

$tester->run(array('command' => 'list', '--verbose' => 3));
$this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');

$tester->run(array('command' => 'list', '--verbose' => 4));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');

$tester->run(array('command' => 'list', '-v' => true));
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');

Expand Down
Expand Up @@ -6,7 +6,7 @@
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
Expand Down
Expand Up @@ -6,7 +6,7 @@
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
Expand Down
Expand Up @@ -39,8 +39,11 @@
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages.</description>
<option name="--verbose" shortcut="-v" accept_value="1" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)</description>
<defaults>
<default>1</default>
</defaults>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
Expand Down Expand Up @@ -109,8 +112,11 @@
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages.</description>
<option name="--verbose" shortcut="-v" accept_value="1" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)</description>
<defaults>
<default>1</default>
</defaults>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
Expand Down
Expand Up @@ -16,8 +16,11 @@
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages.</description>
<option name="--verbose" shortcut="-v" accept_value="1" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)</description>
<defaults>
<default>1</default>
</defaults>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
Expand Down
Expand Up @@ -6,7 +6,7 @@
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
Expand Down
Expand Up @@ -6,7 +6,7 @@ Usage:
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v Increase verbosity of messages.
--verbose -v Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)
--version -V Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
Expand Down
Expand Up @@ -11,7 +11,7 @@ Options:
--raw To output raw command help
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v) Increase verbosity of messages.
--verbose (-v) Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum) (default: 1)
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
Expand Down
Expand Up @@ -8,7 +8,7 @@
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message.
<info>--quiet</info> (-q) Do not output any message.
<info>--verbose</info> (-v) Increase verbosity of messages.
<info>--verbose</info> (-v) Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)<comment> (default: 1)</comment>
<info>--version</info> (-V) Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
Expand Down
Expand Up @@ -19,8 +19,11 @@
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages.</description>
<option name="--verbose" shortcut="-v" accept_value="1" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages. Can be between 1 (normal, default), 2 (more verbose) and 3 (maximum)</description>
<defaults>
<default>1</default>
</defaults>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version.</description>
Expand Down

0 comments on commit 16cdb61

Please sign in to comment.