From 16cdb6128e4e01405c1f85514c8627abbbed96b7 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Thu, 11 Apr 2013 14:08:21 +0300 Subject: [PATCH] Added more verbosity levels --- src/Symfony/Component/Console/Application.php | 16 ++++++++++++++-- .../Component/Console/Output/OutputInterface.php | 12 +++++++----- .../Component/Console/Tests/ApplicationTest.php | 16 ++++++++++++++-- .../Tests/Fixtures/application_astext1.txt | 2 +- .../Tests/Fixtures/application_astext2.txt | 2 +- .../Tests/Fixtures/application_asxml1.txt | 14 ++++++++++---- .../Tests/Fixtures/application_asxml2.txt | 7 +++++-- .../Tests/Fixtures/application_gethelp.txt | 2 +- .../Console/Tests/Fixtures/application_run1.txt | 2 +- .../Console/Tests/Fixtures/application_run2.txt | 2 +- .../Console/Tests/Fixtures/command_astext.txt | 2 +- .../Console/Tests/Fixtures/command_asxml.txt | 7 +++++-- 12 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 0290b5bcd9..4101426c91 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -184,10 +184,22 @@ class Application 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()); @@ -917,7 +929,7 @@ class Application 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.'), diff --git a/src/Symfony/Component/Console/Output/OutputInterface.php b/src/Symfony/Component/Console/Output/OutputInterface.php index 6ca9f371b1..4d7606cb53 100644 --- a/src/Symfony/Component/Console/Output/OutputInterface.php +++ b/src/Symfony/Component/Console/Output/OutputInterface.php @@ -22,13 +22,15 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface; */ 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. diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index f2614bfa37..562c2149b5 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -406,8 +406,8 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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() @@ -502,6 +502,18 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt index 2f692c07e0..310cd7c166 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt @@ -6,7 +6,7 @@ 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. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt index 1457bf793d..fba909afdc 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt @@ -6,7 +6,7 @@ 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. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt index 965bc704f2..090367a358 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt @@ -39,8 +39,11 @@ - - - -