Switch working directory according to --working-dir option.
parent
4ac678454d
commit
6f317b7a6b
|
@ -93,8 +93,13 @@ class Application extends BaseApplication
|
|||
$startTime = microtime(true);
|
||||
}
|
||||
|
||||
$oldWorkingDir = getcwd();
|
||||
$this->switchWorkingDir($input);
|
||||
|
||||
$result = parent::doRun($input, $output);
|
||||
|
||||
chdir($oldWorkingDir);
|
||||
|
||||
if (isset($startTime)) {
|
||||
$output->writeln('<info>Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s');
|
||||
}
|
||||
|
@ -102,6 +107,19 @@ class Application extends BaseApplication
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private function switchWorkingDir(InputInterface $input)
|
||||
{
|
||||
$workingDir = $input->getParameterOption(array('--working-dir', '-d'), getcwd());
|
||||
if (!is_dir($workingDir)) {
|
||||
throw new \RuntimeException('Invalid working directoy specified.');
|
||||
}
|
||||
chdir($workingDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $required
|
||||
* @return \Composer\Composer
|
||||
|
|
Loading…
Reference in New Issue