From c53fe46e38d0234c5dd290380a67b07c43eacbd4 Mon Sep 17 00:00:00 2001 From: Daniel Gomes Date: Sat, 14 Dec 2013 13:57:08 +0100 Subject: [PATCH 1/4] [Console] Added the possibility to set a different default command * Added new method `setDefaultCommand` and changed the logic in the doRun method in order to allow it to run by default a Command setted by the user instead of the `ListCommand` * Added tests * Should fix #8058 * Updated CHANGELOG --- src/Symfony/Component/Console/Application.php | 16 +++++++- src/Symfony/Component/Console/CHANGELOG.md | 1 + .../Console/Tests/ApplicationTest.php | 37 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 94913cd23a176..c922424e5d786 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -67,6 +67,7 @@ class Application private $helperSet; private $dispatcher; private $terminalDimensions; + private $defaultCommand; /** * Constructor. @@ -80,6 +81,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->name = $name; $this->version = $version; + $this->defaultCommand = 'list'; $this->helperSet = $this->getDefaultHelperSet(); $this->definition = $this->getDefaultInputDefinition(); @@ -179,8 +181,8 @@ public function doRun(InputInterface $input, OutputInterface $output) } if (!$name) { - $name = 'list'; - $input = new ArrayInput(array('command' => 'list')); + $name = $this->defaultCommand; + $input = new ArrayInput(array('command' => $this->defaultCommand)); } // the command name MUST be the first element of the input @@ -1086,4 +1088,14 @@ private function findAlternatives($name, $collection) return array_keys($alternatives); } + + /** + * Sets the default Command instead of using the ListCommand + * + * @param string $commandName The Command name + */ + public function setDefaultCommand($commandName) + { + $this->defaultCommand = $commandName; + } } diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index 313699836d2c7..19d03ca3039ea 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.5.0 ----- +* added a way to set a default command instead of `ListCommand` * added a way to set the process name of a command 2.4.0 diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 719a98b32b730..b33bbd17bb330 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -881,6 +881,28 @@ protected function getDispatcher() return $dispatcher; } + + public function testSetRunCustomDefaultCommand() + { + $command = new \FooCommand(); + + $application = new Application(); + $application->setAutoExit(false); + $application->add($command); + $application->setDefaultCommand($command->getName()); + + $tester = new ApplicationTester($application); + $tester->run(array()); + $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + + $application = new CustomDefaultCommandApplication(); + $application->setAutoExit(false); + + $tester = new ApplicationTester($application); + $tester->run(array()); + + $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + } } class CustomApplication extends Application @@ -905,3 +927,18 @@ protected function getDefaultHelperSet() return new HelperSet(array(new FormatterHelper())); } } + +class CustomDefaultCommandApplication extends Application +{ + /** + * Overwrites the constructor in order to set a different default command. + */ + public function __construct() + { + parent::__construct(); + + $command = new \FooCommand(); + $this->add($command); + $this->setDefaultCommand($command->getName()); + } +} From d53bd869d506bd8c3551a31c8e65f7e994d11f29 Mon Sep 17 00:00:00 2001 From: Daniel Gomes Date: Tue, 7 Jan 2014 10:35:16 +0000 Subject: [PATCH 2/4] Removed white spaces --- src/Symfony/Component/Console/Tests/ApplicationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index b33bbd17bb330..51d99eaf20bc8 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -893,7 +893,7 @@ public function testSetRunCustomDefaultCommand() $tester = new ApplicationTester($application); $tester->run(array()); - $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); $application = new CustomDefaultCommandApplication(); $application->setAutoExit(false); @@ -901,7 +901,7 @@ public function testSetRunCustomDefaultCommand() $tester = new ApplicationTester($application); $tester->run(array()); - $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); } } From e2da1c380cdb46864b8dc6b4bb92902973dd776d Mon Sep 17 00:00:00 2001 From: Daniel Gomes Date: Tue, 7 Jan 2014 14:47:47 +0000 Subject: [PATCH 3/4] Applyed @fabpot suggestions --- src/Symfony/Component/Console/Application.php | 2 +- src/Symfony/Component/Console/Tests/ApplicationTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index c922424e5d786..16b081cb3becc 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -1090,7 +1090,7 @@ private function findAlternatives($name, $collection) } /** - * Sets the default Command instead of using the ListCommand + * Sets the default Command name * * @param string $commandName The Command name */ diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 51d99eaf20bc8..f301fafdb6c60 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -893,7 +893,7 @@ public function testSetRunCustomDefaultCommand() $tester = new ApplicationTester($application); $tester->run(array()); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); $application = new CustomDefaultCommandApplication(); $application->setAutoExit(false); @@ -901,7 +901,7 @@ public function testSetRunCustomDefaultCommand() $tester = new ApplicationTester($application); $tester->run(array()); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default setted command if different from \'list\' command'); + $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); } } From c070b804f250fbf02524af5e8441a8bfd6a278e7 Mon Sep 17 00:00:00 2001 From: Daniel Gomes Date: Tue, 7 Jan 2014 15:18:13 +0000 Subject: [PATCH 4/4] Added dot at the end of sentence --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 16b081cb3becc..5247b9f6dbb64 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -1090,7 +1090,7 @@ private function findAlternatives($name, $collection) } /** - * Sets the default Command name + * Sets the default Command name. * * @param string $commandName The Command name */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy