1
0
Fork 0

Add ability to call composer from within subdirectories of a project, fixes #6426

pull/6592/head
Jordi Boggiano 2017-08-07 10:36:02 +02:00
parent c2da4e0e0e
commit ec2722f879
1 changed files with 18 additions and 0 deletions

View File

@ -126,6 +126,24 @@ class Application extends BaseApplication
}
}
// prompt user for dir change if no composer.json is present in current dir
if ($io->isInteractive() && !in_array($commandName, array('init', 'about', 'help', 'diagnose', 'self-update', 'global'), true) && !file_exists('./composer.json')) {
$dir = dirname(getcwd());
$home = realpath(getenv('HOME') ?: getenv('USERPROFILE') ?: '/');
// abort when we reach the home dir or top of the filesystem
while (dirname($dir) !== $dir && $dir !== $home) {
if (file_exists($dir.'/composer.json')) {
if ($io->askConfirmation('<info>No composer.json in current directory, do you want to use the one at '.$dir.'?</info> [<comment>Y,n</comment>]? ', true)) {
$oldWorkingDir = getcwd();
chdir($dir);
}
break;
}
$dir = dirname($dir);
}
}
if (!$this->disablePluginsByDefault && !$this->hasPluginCommands && 'global' !== $commandName) {
try {
foreach ($this->getPluginCommands() as $command) {