Browse Source

Make sure a constraint is provided with input requirements

Jordi Boggiano 12 years ago
parent
commit
1443ea25f9
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/Composer/Command/InitCommand.php

+ 9 - 0
src/Composer/Command/InitCommand.php

@@ -260,6 +260,15 @@ EOT
         if ($requires) {
             foreach ($requires as $key => $requirement) {
                 $requires[$key] = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', $requirement);
+                if (false === strpos($requires[$key], ' ') && $input->isInteractive()) {
+                    $question = $dialog->getQuestion('Please provide a version constraint for the '.$requirement.' requirement');
+                    if ($constraint = $dialog->ask($output, $question)) {
+                        $requires[$key] .= ' ' . $constraint;
+                    }
+                }
+                if (false === strpos($requires[$key], ' ')) {
+                    throw new \InvalidArgumentException('The requirement '.$requirement.' must contain a version constraint');
+                }
             }
 
             return $requires;