Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60eb4f6

Browse files
committed
bug #9566 [Console] Revert BC-break for verbose option value (chEbba)
This PR was merged into the master branch. Discussion ---------- [Console] Revert BC-break for verbose option value | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9285 | License | MIT | Doc PR | ~ Closes #9285 ---- PR #8835 "fixed" the input value for verbosity option with `VALUE_OPTIONAL`. And syntax like ``` cli.php -v command cli.php --verbose command ``` Is broken now, because `ArgvInput` tries to use argument as verbose value (#9285). For now i added a test for this case and revert this changes. Commits ------- 432bbe1 [Console] Revert a28eb8 because of BC break 5e03e9a [Console] Add test for --verbose before argument
2 parents f00146f + 432bbe1 commit 60eb4f6

File tree

11 files changed

+49
-39
lines changed

11 files changed

+49
-39
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -846,16 +846,12 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
846846

847847
if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
848848
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
849-
} elseif ($input->hasParameterOption(array('--verbose', '-v', '-vv', '-vvv'))) {
850-
$verbosity = 1;
851-
if ($input->hasParameterOption('--verbose')) {
852-
$verbosity = min(max((int) $input->getParameterOption('--verbose'), 1), 3);
853-
}
854-
if ($input->hasParameterOption('-vvv') || $verbosity === 3) {
849+
} else {
850+
if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
855851
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
856-
} elseif ($input->hasParameterOption('-vv') || $verbosity === 2) {
852+
} elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
857853
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
858-
} else {
854+
} elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
859855
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
860856
}
861857
}
@@ -930,7 +926,7 @@ protected function getDefaultInputDefinition()
930926

931927
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
932928
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
933-
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_OPTIONAL, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
929+
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
934930
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version.'),
935931
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
936932
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Helper\HelperSet;
1616
use Symfony\Component\Console\Helper\FormatterHelper;
17+
use Symfony\Component\Console\Input\ArgvInput;
1718
use Symfony\Component\Console\Input\ArrayInput;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputArgument;
@@ -22,6 +23,7 @@
2223
use Symfony\Component\Console\Output\NullOutput;
2324
use Symfony\Component\Console\Output\Output;
2425
use Symfony\Component\Console\Output\OutputInterface;
26+
use Symfony\Component\Console\Output\StreamOutput;
2527
use Symfony\Component\Console\Tester\ApplicationTester;
2628
use Symfony\Component\Console\Event\ConsoleCommandEvent;
2729
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
@@ -564,9 +566,6 @@ public function testRun()
564566
$tester->run(array('command' => 'list', '--verbose' => true));
565567
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
566568

567-
$tester->run(array('command' => 'list', '--verbose' => 0));
568-
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if smaller --verbose level is passed');
569-
570569
$tester->run(array('command' => 'list', '--verbose' => 1));
571570
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed');
572571

@@ -577,7 +576,7 @@ public function testRun()
577576
$this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');
578577

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

582581
$tester->run(array('command' => 'list', '-v' => true));
583582
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
@@ -601,6 +600,29 @@ public function testRun()
601600
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
602601
}
603602

603+
/**
604+
* Issue #9285
605+
*
606+
* If the "verbose" option is just before an argument in ArgvInput,
607+
* an argument value should not be treated as verbosity value.
608+
* This test will fail with "Not enough arguments." if broken
609+
*/
610+
public function testVerboseValueNotBreakArguments()
611+
{
612+
$application = new Application();
613+
$application->setAutoExit(false);
614+
$application->setCatchExceptions(false);
615+
$application->add(new \FooCommand());
616+
617+
$output = new StreamOutput(fopen('php://memory', 'w', false));
618+
619+
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
620+
$application->run($input, $output);
621+
622+
$input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar'));
623+
$application->run($input, $output);
624+
}
625+
604626
public function testRunReturnsIntegerExitCode()
605627
{
606628
$exception = new \Exception('', 4);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":null},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}
1+
{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}

src/Symfony/Component/Console/Tests/Fixtures/application_1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ To display the list of available commands, please use the <info>list</info> comm
8787

8888
* Name: `--verbose`
8989
* Shortcut: `-v|-vv|-vvv`
90-
* Accept value: yes
90+
* Accept value: no
9191
* Is value required: no
9292
* Is multiple: no
9393
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
94-
* Default: `NULL`
94+
* Default: `false`
9595

9696
**version:**
9797

src/Symfony/Component/Console/Tests/Fixtures/application_1.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
4242
<description>Do not output any message.</description>
4343
</option>
44-
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="1" is_value_required="0" is_multiple="0">
44+
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
4545
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
46-
<defaults/>
4746
</option>
4847
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
4948
<description>Display this application version.</description>

0 commit comments

Comments
 (0)