1
0
Fork 0

Add interactive option to install dependencies after running init command (#7521)

* Add interactive option to install dependencies after running init command

* Only ask to install dependencies when dependencies where defined
pull/7806/head
Shalvah 2018-11-26 12:57:38 +01:00 committed by Jordi Boggiano
parent f9234222d1
commit 42e88ac27a
1 changed files with 25 additions and 0 deletions

View File

@ -22,6 +22,7 @@ use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@ -145,6 +146,11 @@ EOT
}
}
}
$question = 'Would you like to install dependencies now [<comment>yes</comment>]? ';
if ($input->isInteractive() && $this->hasDependencies($options) && $io->askConfirmation($question, true)) {
$this->installDependencies($output);
}
}
/**
@ -767,4 +773,23 @@ EOT
return array_keys(array_slice($similarPackages, 0, 5));
}
private function installDependencies($output)
{
try {
$installCommand = $this->getApplication()->find('install');
$installCommand->run(new ArrayInput(array()), $output);
} catch (\Exception $e) {
$this->getIO()->writeError('Could not install dependencies. Run `composer install` to see more information.');
}
}
private function hasDependencies($options)
{
$requires = (array) $options['require'];
$devRequires = isset($options['require-dev']) ? (array) $options['require-dev'] : array();
return !empty($requires) || !empty($devRequires);
}
}