From 1213d368f67cd802d6ac659272a3aeba6ebed35b Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:16:18 +0200 Subject: [PATCH 01/13] Updated tests for new QuestionHelper flow --- tests/Composer/Test/IO/ConsoleIOTest.php | 89 ++++++++++++++---------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index d0af8cb42..a61b310da 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -129,20 +129,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) + $helperMock + ->expects($this->once()) ->method('ask') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('default')); - $helperMock->expects($this->once()) - ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\Question') + ) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $setMock + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; + + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->ask('Why?', 'default'); } @@ -150,20 +157,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) - ->method('askConfirmation') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('default')); - $helperMock->expects($this->once()) + $helperMock + ->expects($this->once()) + ->method('ask') + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\ConfirmationQuestion') + ) + ; + + $setMock + ->expects($this->once()) ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->askConfirmation('Why?', 'default'); } @@ -171,22 +185,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) - ->method('askAndValidate') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('validator'), - $this->equalTo(10), - $this->equalTo('default')); - $helperMock->expects($this->once()) + $helperMock + ->expects($this->once()) + ->method('ask') + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\Question') + ) + ; + + $setMock + ->expects($this->once()) ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->askAndValidate('Why?', 'validator', 10, 'default'); } From 8cc6e4f67d02e660a133a69fbec8d5fad70e3ee4 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:06:53 +0200 Subject: [PATCH 02/13] Fixed two camelcase names --- tests/Composer/Test/IO/ConsoleIOTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index a61b310da..a300350b9 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -224,7 +224,7 @@ class ConsoleIOTest extends TestCase ); } - public function testgetAuthenticationWhenDidNotSet() + public function testGetAuthenticationWhenDidNotSet() { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); @@ -238,7 +238,7 @@ class ConsoleIOTest extends TestCase ); } - public function testhasAuthentication() + public function testHasAuthentication() { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); From ee4044efcdb72724f42e6096efac9cab18b3c573 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:09:15 +0200 Subject: [PATCH 03/13] Adjusted interface to reflect values from Console --- src/Composer/IO/IOInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index 0fd63fe4a..7dc9f5a09 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -123,14 +123,14 @@ interface IOInterface * * @param string|array $question The question to ask * @param callback $validator A PHP callback - * @param bool|integer $attempts Max number of times to ask before giving up (false by default, which means infinite) + * @param null|integer $attempts Max number of times to ask before giving up (default of null means infinite) * @param string $default The default answer if none is given by the user * * @return mixed * * @throws \Exception When any of the validators return an error */ - public function askAndValidate($question, $validator, $attempts = false, $default = null); + public function askAndValidate($question, $validator, $attempts = null, $default = null); /** * Asks a question to the user and hide the answer. From 7279c25839db14f5f28f25efdb7f366c9e3af92b Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:09:56 +0200 Subject: [PATCH 04/13] Switched to QuestionHelper --- src/Composer/IO/ConsoleIO.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 9300befad..10e617dc2 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -16,6 +16,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; use Symfony\Component\Process\ExecutableFinder; /** @@ -208,10 +210,11 @@ class ConsoleIO extends BaseIO $output = $output->getErrorOutput(); } - /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */ - $dialog = $this->helperSet->get('dialog'); + /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ + $helper = $this->helperSet->get('question'); + $question = new Question($question, $default); - return $dialog->ask($output, $question, $default); + return $helper->ask($this->input, $output, $question); } /** @@ -225,16 +228,17 @@ class ConsoleIO extends BaseIO $output = $output->getErrorOutput(); } - /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */ - $dialog = $this->helperSet->get('dialog'); + /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ + $helper = $this->helperSet->get('question'); + $question = new ConfirmationQuestion($question, $default); - return $dialog->askConfirmation($output, $question, $default); + return $helper->ask($this->input, $output, $question); } /** * {@inheritDoc} */ - public function askAndValidate($question, $validator, $attempts = false, $default = null) + public function askAndValidate($question, $validator, $attempts = null, $default = null) { $output = $this->output; @@ -242,10 +246,13 @@ class ConsoleIO extends BaseIO $output = $output->getErrorOutput(); } - /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */ - $dialog = $this->helperSet->get('dialog'); + /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ + $helper = $this->helperSet->get('question'); + $question = new Question($question, $default); + $question->setValidator($validator); + $question->setMaxAttempts($attempts); - return $dialog->askAndValidate($output, $question, $validator, $attempts, $default); + return $helper->ask($this->input, $output, $question); } /** From fb5394ce70d60f73274586d184f3b236387db5b5 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:10:17 +0200 Subject: [PATCH 05/13] Use constants directly --- src/Composer/IO/ConsoleIO.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 10e617dc2..85095d951 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -83,7 +83,7 @@ class ConsoleIO extends BaseIO */ public function isVeryVerbose() { - return $this->output->getVerbosity() >= 3; // OutputInterface::VERSOBITY_VERY_VERBOSE + return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE; } /** @@ -91,7 +91,7 @@ class ConsoleIO extends BaseIO */ public function isDebug() { - return $this->output->getVerbosity() >= 4; // OutputInterface::VERBOSITY_DEBUG + return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG; } /** From e7c044d4b2721d41a914b60c5879d7b0cdfdf653 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:10:27 +0200 Subject: [PATCH 06/13] Remove dead code --- src/Composer/IO/ConsoleIO.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 85095d951..366c67483 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -160,12 +160,6 @@ class ConsoleIO extends BaseIO */ private function doOverwrite($messages, $newline, $size, $stderr) { - if (true === $stderr && $this->output instanceof ConsoleOutputInterface) { - $output = $this->output->getErrorOutput(); - } else { - $output = $this->output; - } - // messages can be an array, let's convert it to string anyway $messages = join($newline ? "\n" : '', (array) $messages); From 00fcd63c04044f34ebdc2b7e7435b4a45d6f0682 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:10:44 +0200 Subject: [PATCH 07/13] Remove redundant helper --- src/Composer/Command/Helper/DialogHelper.php | 36 -------------------- src/Composer/Console/Application.php | 12 ------- 2 files changed, 48 deletions(-) delete mode 100644 src/Composer/Command/Helper/DialogHelper.php diff --git a/src/Composer/Command/Helper/DialogHelper.php b/src/Composer/Command/Helper/DialogHelper.php deleted file mode 100644 index 6fb64f27e..000000000 --- a/src/Composer/Command/Helper/DialogHelper.php +++ /dev/null @@ -1,36 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Command\Helper; - -use Symfony\Component\Console\Helper\DialogHelper as BaseDialogHelper; - -class DialogHelper extends BaseDialogHelper -{ - /** - * Build text for asking a question. For example: - * - * "Do you want to continue [yes]:" - * - * @param string $question The question you want to ask - * @param mixed $default Default value to add to message, if false no default will be shown - * @param string $sep Separation char for between message and user input - * - * @return string - */ - public function getQuestion($question, $default = null, $sep = ':') - { - return $default !== null ? - sprintf('%s [%s]%s ', $question, $default, $sep) : - sprintf('%s%s ', $question, $sep); - } -} diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 2ccaec890..b2f9d5e7b 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -20,7 +20,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Formatter\OutputFormatter; use Composer\Command; -use Composer\Command\Helper\DialogHelper; use Composer\Composer; use Composer\Factory; use Composer\IO\IOInterface; @@ -321,15 +320,4 @@ class Application extends BaseApplication return $definition; } - - /** - * {@inheritDoc} - */ - protected function getDefaultHelperSet() - { - $helperSet = parent::getDefaultHelperSet(); - $helperSet->set(new DialogHelper()); - - return $helperSet; - } } From 3dae4cd5173666d2528ffc3b0bc0592d174018cc Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:20:32 +0200 Subject: [PATCH 08/13] Switch to QuestionHelper --- src/Composer/Command/RemoveCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index 8821bd991..591548d2a 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -74,9 +74,8 @@ EOT $json->removeLink($type, $package); } elseif (isset($composer[$altType][$package])) { $this->getIO()->writeError(''.$package.' could not be found in '.$type.' but it is present in '.$altType.''); - $dialog = $this->getHelperSet()->get('dialog'); if ($this->getIO()->isInteractive()) { - if ($dialog->askConfirmation($output, $dialog->getQuestion('Do you want to remove it from '.$altType, 'yes', '?'), true)) { + if ($this->getIO()->askConfirmation('Do you want to remove it from '.$altType.' [yes]?', true)) { $json->removeLink($altType, $package); } } From bef46a17dc107112e4fe901b88ffc6bb0b09e74f Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:22:09 +0200 Subject: [PATCH 09/13] Moved method --- src/Composer/Command/InitCommand.php | 37 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index ae3fc8330..47fa20c28 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -38,22 +38,6 @@ class InitCommand extends Command private $gitConfig; private $pool; - public function parseAuthorString($author) - { - if (preg_match('/^(?P[- \.,\p{L}\p{N}\'’]+) <(?P.+?)>$/u', $author, $match)) { - if ($this->isValidEmail($match['email'])) { - return array( - 'name' => trim($match['name']), - 'email' => $match['email'] - ); - } - } - - throw new \InvalidArgumentException( - 'Invalid author string. Must be in the format: '. - 'John Smith ' - ); - } protected function configure() { @@ -293,6 +277,27 @@ EOT $input->setOption('require-dev', $devRequirements); } + /** + * @param string $author + * @return array + */ + public function parseAuthorString($author) + { + if (preg_match('/^(?P[- \.,\p{L}\p{N}\'’]+) <(?P.+?)>$/u', $author, $match)) { + if ($this->isValidEmail($match['email'])) { + return array( + 'name' => trim($match['name']), + 'email' => $match['email'] + ); + } + } + + throw new \InvalidArgumentException( + 'Invalid author string. Must be in the format: '. + 'John Smith ' + ); + } + protected function findPackages($name) { return $this->getRepos()->search($name); From 290fafa156793a0757253e53d71c7af392c7fd7d Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:22:54 +0200 Subject: [PATCH 10/13] Docs and whitespace --- src/Composer/Command/InitCommand.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 47fa20c28..3dc5b9ece 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -33,12 +33,18 @@ use Symfony\Component\Process\ExecutableFinder; */ class InitCommand extends Command { + /** @var CompositeRepository */ protected $repos; + /** @var array */ private $gitConfig; + + /** @var Pool */ private $pool; - + /** + * {@inheritdoc} + */ protected function configure() { $this @@ -67,6 +73,9 @@ EOT ; } + /** + * {@inheritdoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); @@ -133,12 +142,16 @@ EOT } } + /** + * {@inheritdoc} + */ protected function interact(InputInterface $input, OutputInterface $output) { $git = $this->getGitConfig(); $dialog = $this->getHelperSet()->get('dialog'); $formatter = $this->getHelperSet()->get('formatter'); + $this->getIO()->writeError(array( '', $formatter->formatBlock('Welcome to the Composer config generator', 'bg=blue;fg=white', true), From 0fbc00f3fb83c2413e5e924b46da2920e997d357 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:23:13 +0200 Subject: [PATCH 11/13] Switch to QuestionHelper --- src/Composer/Command/InitCommand.php | 96 +++++++++++++--------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 3dc5b9ece..2008db75d 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -78,8 +78,6 @@ EOT */ protected function execute(InputInterface $input, OutputInterface $output) { - $dialog = $this->getHelperSet()->get('dialog'); - $whitelist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license'); $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist))); @@ -107,16 +105,11 @@ EOT } $file = new JsonFile('composer.json'); - $json = $file->encode($options); if ($input->isInteractive()) { - $this->getIO()->writeError(array( - '', - $json, - '' - )); - if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) { + $this->getIO()->writeError(array('', $json, '')); + if (!$this->getIO()->askConfirmation('Do you confirm generation [yes]? ', true)) { $this->getIO()->writeError('Command aborted'); return 1; @@ -133,9 +126,9 @@ EOT } if (!$this->hasVendorIgnore($ignoreFile)) { - $question = 'Would you like the vendor directory added to your .gitignore [yes]?'; + $question = 'Would you like the vendor directory added to your .gitignore [yes]? '; - if ($dialog->askConfirmation($output, $question, true)) { + if ($this->getIO()->askConfirmation($question, true)) { $this->addVendorIgnore($ignoreFile); } } @@ -149,7 +142,6 @@ EOT { $git = $this->getGitConfig(); - $dialog = $this->getHelperSet()->get('dialog'); $formatter = $this->getHelperSet()->get('formatter'); $this->getIO()->writeError(array( @@ -189,9 +181,8 @@ EOT } } - $name = $dialog->askAndValidate( - $output, - $dialog->getQuestion('Package name (/)', $name), + $name = $this->getIO()->askAndValidate( + 'Package name (/) ['.$name.']: ', function ($value) use ($name) { if (null === $value) { return $name; @@ -204,14 +195,15 @@ EOT } return $value; - } + }, + null, + $name ); $input->setOption('name', $name); $description = $input->getOption('description') ?: false; - $description = $dialog->ask( - $output, - $dialog->getQuestion('Description', $description), + $description = $this->getIO()->ask( + 'Description ['.$description.']: ', $description ); $input->setOption('description', $description); @@ -223,22 +215,22 @@ EOT } $self = $this; - $author = $dialog->askAndValidate( - $output, - $dialog->getQuestion('Author', $author), + $author = $this->getIO()->askAndValidate( + 'Author ['.$author.']: ', function ($value) use ($self, $author) { $value = $value ?: $author; $author = $self->parseAuthorString($value); return sprintf('%s <%s>', $author['name'], $author['email']); - } + }, + null, + $author ); $input->setOption('author', $author); - $minimumStability = $input->getOption('stability') ?: ''; - $minimumStability = $dialog->askAndValidate( - $output, - $dialog->getQuestion('Minimum Stability', $minimumStability), + $minimumStability = $input->getOption('stability') ?: null; + $minimumStability = $this->getIO()->askAndValidate( + 'Minimum Stability ['.$minimumStability.']: ', function ($value) use ($self, $minimumStability) { if (null === $value) { return $minimumStability; @@ -252,39 +244,38 @@ EOT } return $value; - } + }, + null, + $minimumStability ); $input->setOption('stability', $minimumStability); $type = $input->getOption('type') ?: false; - $type = $dialog->ask( - $output, - $dialog->getQuestion('Package Type', $type), + $type = $this->getIO()->ask( + 'Package Type ['.$type.']: ', $type ); $input->setOption('type', $type); $license = $input->getOption('license') ?: false; - $license = $dialog->ask( - $output, - $dialog->getQuestion('License', $license), + $license = $this->getIO()->ask( + 'License ['.$license.']: ', $license ); $input->setOption('license', $license); - $this->getIO()->writeError(array( - '', - 'Define your dependencies.', - '' - )); + $this->getIO()->writeError(array('', 'Define your dependencies.', '')); + $question = 'Would you like to define your dependencies (require) interactively [yes]? '; $requirements = array(); - if ($dialog->askConfirmation($output, $dialog->getQuestion('Would you like to define your dependencies (require) interactively', 'yes', '?'), true)) { + if ($this->getIO()->askConfirmation($question, true)) { $requirements = $this->determineRequirements($input, $output, $input->getOption('require')); } $input->setOption('require', $requirements); + + $question = 'Would you like to define your dev dependencies (require-dev) interactively [yes]? '; $devRequirements = array(); - if ($dialog->askConfirmation($output, $dialog->getQuestion('Would you like to define your dev dependencies (require-dev) interactively', 'yes', '?'), true)) { + if ($this->getIO()->askConfirmation($question, true)) { $devRequirements = $this->determineRequirements($input, $output, $input->getOption('require-dev')); } $input->setOption('require-dev', $devRequirements); @@ -330,9 +321,6 @@ EOT protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array()) { - $dialog = $this->getHelperSet()->get('dialog'); - $prompt = $dialog->getQuestion('Search for a package', false, ':'); - if ($requires) { $requires = $this->normalizeRequirements($requires); $result = array(); @@ -357,7 +345,7 @@ EOT } $versionParser = new VersionParser(); - while (null !== $package = $dialog->ask($output, $prompt)) { + while (null !== $package = $this->getIO()->ask('Search for a package: ')) { $matches = $this->findPackages($package); if (count($matches)) { @@ -410,7 +398,12 @@ EOT throw new \Exception('Not a valid selection'); }; - $package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add, or the complete package name if it is not listed', false, ':'), $validator, 3); + $package = $this->getIO()->askAndValidate( + 'Enter package # to add, or the complete package name if it is not listed: ', + $validator, + 3, + false + ); } // no constraint yet, determine the best version automatically @@ -421,12 +414,13 @@ EOT return $input ?: false; }; - $constraint = $dialog->askAndValidate( - $output, - $dialog->getQuestion('Enter the version constraint to require (or leave blank to use the latest version)', false, ':'), + $constraint = $this->getIO()->askAndValidate( + 'Enter the version constraint to require (or leave blank to use the latest version): ', $validator, - 3) - ; + 3, + false + ); + if (false === $constraint) { $constraint = $this->findBestVersionForPackage($input, $package); From e810a7913eee474576be809f542d57bdd74f595e Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:29:19 +0200 Subject: [PATCH 12/13] Space after ? (so it doesnt glue answer to ?) --- src/Composer/Command/RemoveCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index 591548d2a..3779b09e9 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -75,7 +75,7 @@ EOT } elseif (isset($composer[$altType][$package])) { $this->getIO()->writeError(''.$package.' could not be found in '.$type.' but it is present in '.$altType.''); if ($this->getIO()->isInteractive()) { - if ($this->getIO()->askConfirmation('Do you want to remove it from '.$altType.' [yes]?', true)) { + if ($this->getIO()->askConfirmation('Do you want to remove it from '.$altType.' [yes]? ', true)) { $json->removeLink($altType, $package); } } From acd14864064aa545113ed8899e6f0254f55dc00e Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:35:25 +0200 Subject: [PATCH 13/13] Mark method as @private --- src/Composer/Command/InitCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 2008db75d..70411736a 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -282,6 +282,7 @@ EOT } /** + * @private * @param string $author * @return array */