Fixed validator to accept 'a/b' and 'a/b ~2.3'
parent
373c688f8c
commit
3bf1ee939b
|
@ -328,6 +328,7 @@ EOT
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$versionParser = new VersionParser();
|
||||||
while (null !== $package = $dialog->ask($output, $prompt)) {
|
while (null !== $package = $dialog->ask($output, $prompt)) {
|
||||||
$matches = $this->findPackages($package);
|
$matches = $this->findPackages($package);
|
||||||
|
|
||||||
|
@ -353,22 +354,32 @@ EOT
|
||||||
$output->writeln($choices);
|
$output->writeln($choices);
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
|
||||||
$validator = function ($selection) use ($matches) {
|
$validator = function ($selection) use ($matches, $versionParser) {
|
||||||
if ('' === $selection) {
|
if ('' === $selection) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($selection) && preg_match('{^\s*(\S+)\s+(\S.*)\s*$}', $selection, $matches)) {
|
if (is_numeric($selection) && isset($matches[(int) $selection])) {
|
||||||
return $matches[1].' '.$matches[2];
|
$package = $matches[(int) $selection];
|
||||||
|
|
||||||
|
return $package['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($matches[(int) $selection])) {
|
if (preg_match('{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}', $selection, $packageMatches)) {
|
||||||
throw new \Exception('Not a valid selection');
|
if (isset($packageMatches['version'])) {
|
||||||
|
// parsing `acme/example ~2.3`
|
||||||
|
|
||||||
|
// validate version constraint
|
||||||
|
$versionParser->parseConstraints($packageMatches['version']);
|
||||||
|
|
||||||
|
return $packageMatches['name'].' '.$packageMatches['version'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// parsing `acme/example`
|
||||||
|
return $packageMatches['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$package = $matches[(int) $selection];
|
throw new \Exception('Not a valid selection');
|
||||||
|
|
||||||
return $package['name'];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add, or the complete package name if it is not listed', false, ':'), $validator, 3);
|
$package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add, or the complete package name if it is not listed', false, ':'), $validator, 3);
|
||||||
|
|
Loading…
Reference in New Issue