1
0
Fork 0

update the logic

pull/3639/head
SofHad 2015-01-20 00:12:14 +01:00
parent 6fff09c82a
commit dd9e208bc7
1 changed files with 10 additions and 33 deletions

View File

@ -80,11 +80,10 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$packages = $input->getOption('interactive') ? $this->getPackagesInteractively( $packages = $input->getArgument('packages');
$input, if ($input->getOption('interactive')) {
$output, $packages = $this->getPackagesInteractively($input, $output, $composer, $packages);
$composer }
) : $input->getArgument('packages');
if ($input->getOption('no-custom-installers')) { if ($input->getOption('no-custom-installers')) {
$output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>'); $output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
@ -146,20 +145,10 @@ EOT
return $install->run(); return $install->run();
} }
private function getPackagesInteractively( private function getPackagesInteractively(InputInterface $input, OutputInterface $output, Composer $composer, $packages)
InputInterface $input, {
OutputInterface $output,
Composer $composer
) {
if ($input->getArgument('packages')) {
throw new \InvalidArgumentException(
'The option --interactive does not require an argument'
);
}
$packagesMap = $composer->getRepositoryManager() $packagesMap = $composer->getRepositoryManager()
->getLocalRepository()->getPackages(); ->getLocalRepository()->getPackages();
$config = $composer->getConfig();
$requiredPackageNames = array(); $requiredPackageNames = array();
foreach ( foreach (
@ -174,26 +163,18 @@ EOT
foreach ($packagesMap as $package) { foreach ($packagesMap as $package) {
$InstalledPackageNames[] = $package->getPrettyName(); $InstalledPackageNames[] = $package->getPrettyName();
} }
$names = array_unique(
$autocompleterValues = array_unique(
array_merge($InstalledPackageNames, $requiredPackageNames) array_merge($InstalledPackageNames, $requiredPackageNames)
); );
$vendorDir = $config->get('vendor-dir', true);
$vendorWildcard = sprintf('%s/*', $vendorDir);
$autocompleterValues = array($vendorWildcard);
foreach ($names as $name) {
$autocompleterValues[] = $name;
$autocompleterValues[] = sprintf('%s/%s', $vendorDir, $name);
}
$helper = $this->getHelper('question'); $helper = $this->getHelper('question');
$question = new Question( $question = new Question(
'<comment>Enter package name: </comment>', '<comment>Enter package name: </comment>',
null null
); );
$packages = array(); $packages = is_array($packages) ? $packages : array();
$output->writeln('<info>NB: Empty package ends submission.</info>'); // I couldn't find any better for now! $output->writeln('<info>NB: Empty package ends submission.</info>'); // I couldn't find any better for now!
$continue = true; $continue = true;
@ -204,11 +185,7 @@ EOT
if (is_string($addedPackage)) { if (is_string($addedPackage)) {
if (!in_array($addedPackage, $packages)) { if (!in_array($addedPackage, $packages)) {
$packages[] = $addedPackage; $packages[] = $addedPackage;
if ($addedPackage === $vendorWildcard) {
$autocompleterValues = array();
} else {
$autocompleterValues = array_diff($autocompleterValues, array($addedPackage)); $autocompleterValues = array_diff($autocompleterValues, array($addedPackage));
}
} else { } else {
$output->writeln(sprintf('<error>The package "%s" was already added.</error>', $package)); $output->writeln(sprintf('<error>The package "%s" was already added.</error>', $package));
} }