From 4ac678454dff52c28d0305368331b2f138899234 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 15 Sep 2012 11:36:57 +0200 Subject: [PATCH 1/2] Added --working-dir to definition. --- src/Composer/Console/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 35a589f303c3..2f7403192910 100755 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -163,6 +163,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; } From 6f317b7a6b6f5700077908c4d081f9d9113e635c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 15 Sep 2012 12:29:56 +0200 Subject: [PATCH 2/2] Switch working directory according to --working-dir option. --- src/Composer/Console/Application.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 2f7403192910..60334ee0af0e 100755 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -93,8 +93,13 @@ 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('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 @@ public function doRun(InputInterface $input, OutputInterface $output) 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