Merge pull request #1110 from derrabus/working-dir-feature
Added global --working-dir optionpull/1106/merge
commit
bcf75024c8
|
@ -93,8 +93,13 @@ class Application extends BaseApplication
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oldWorkingDir = getcwd();
|
||||||
|
$this->switchWorkingDir($input);
|
||||||
|
|
||||||
$result = parent::doRun($input, $output);
|
$result = parent::doRun($input, $output);
|
||||||
|
|
||||||
|
chdir($oldWorkingDir);
|
||||||
|
|
||||||
if (isset($startTime)) {
|
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');
|
$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;
|
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
|
* @param bool $required
|
||||||
* @return \Composer\Composer
|
* @return \Composer\Composer
|
||||||
|
@ -163,6 +181,7 @@ class Application extends BaseApplication
|
||||||
{
|
{
|
||||||
$definition = parent::getDefaultInputDefinition();
|
$definition = parent::getDefaultInputDefinition();
|
||||||
$definition->addOption(new InputOption('--profile', null, InputOption::VALUE_NONE, 'Display timing and memory usage information'));
|
$definition->addOption(new InputOption('--profile', null, InputOption::VALUE_NONE, 'Display timing and memory usage information'));
|
||||||
|
$definition->addOption(new InputOption('--working-dir', '-d', InputOption::VALUE_REQUIRED, 'If specified, use the given directory as working directory.'));
|
||||||
|
|
||||||
return $definition;
|
return $definition;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue