From ee7b68c04975992bd06efe725b6f763889d8529c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 16 Feb 2012 20:41:12 +0100 Subject: [PATCH] Allow people to manually enter requirements --- src/Composer/Command/InitCommand.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 56eb2e465..80c487935 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -273,17 +273,23 @@ EOT return false; } + if (!is_numeric($selection) && preg_match('{^\s*(\S+) +(\S.*)\s*}', $selection, $matches)) { + return $matches[1].' '.$matches[2]; + } + if (!isset($matches[(int) $selection])) { throw new \Exception('Not a valid selection'); } - return $matches[(int) $selection]; + $package = $matches[(int) $selection]; + + return sprintf('%s %s', $package->getName(), $package->getPrettyVersion()); }; - $package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add', false, ':'), $validator, 3); + $package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add, or a couple if it is not listed', false, ':'), $validator, 3); if (false !== $package) { - $requires[] = sprintf('%s %s', $package->getName(), $package->getPrettyVersion()); + $requires[] = $package; } } } @@ -300,7 +306,7 @@ EOT { $requires = array(); foreach ($requirements as $requirement) { - list($packageName, $packageVersion) = explode(" ", $requirement); + list($packageName, $packageVersion) = explode(" ", $requirement, 2); $requires[$packageName] = $packageVersion; }