Navigation Menu

Skip to content

Commit

Permalink
Merge pull request composer#1110 from derrabus/working-dir-feature
Browse files Browse the repository at this point in the history
Added global --working-dir option
  • Loading branch information
naderman committed Sep 15, 2012
2 parents 3fa9f10 + 6f317b7 commit bcf7502
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Composer/Console/Application.php
Expand Up @@ -93,15 +93,33 @@ public function doRun(InputInterface $input, OutputInterface $output)
$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');
}

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
Expand Down Expand Up @@ -163,6 +181,7 @@ protected function getDefaultInputDefinition()
{
$definition = parent::getDefaultInputDefinition();
$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;
}
Expand Down

0 comments on commit bcf7502

Please sign in to comment.