1
0
Fork 0

Improve error reporting on global command, fixes #7556

pull/7565/head
Jordi Boggiano 2018-08-16 16:08:31 +02:00
parent b8e8cc2516
commit 020d1f88c7
1 changed files with 17 additions and 2 deletions

View File

@ -13,6 +13,7 @@
namespace Composer\Command; namespace Composer\Command;
use Composer\Factory; use Composer\Factory;
use Composer\Util\Filesystem;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Input\StringInput;
@ -75,8 +76,22 @@ EOT
// change to global dir // change to global dir
$config = Factory::createConfig(); $config = Factory::createConfig();
chdir($config->get('home')); $home = $config->get('home');
$this->getIO()->writeError('<info>Changed current directory to '.$config->get('home').'</info>');
if (!is_dir($home)) {
$fs = new Filesystem();
$fs->ensureDirectoryExists($home);
if (!is_dir($home)) {
throw new \RuntimeException('Could not create home directory');
}
}
try {
chdir($home);
} catch (\Exception $e) {
throw new \RuntimeException('Could not switch to home directory "'.$home.'"', 0, $e);
}
$this->getIO()->writeError('<info>Changed current directory to '.$home.'</info>');
// create new input without "global" command prefix // create new input without "global" command prefix
$input = new StringInput(preg_replace('{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}', '', $input->__toString(), 1)); $input = new StringInput(preg_replace('{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}', '', $input->__toString(), 1));