From c54d6f93e3c5838092363447498ecb366e1e60a2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 16 Dec 2014 14:28:51 +0000 Subject: [PATCH] Add --absolute to resolve absolute paths in config command, otherwise set default back to relative --- doc/03-cli.md | 14 ++++++++------ src/Composer/Command/ConfigCommand.php | 3 ++- src/Composer/Config.php | 6 ++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index 26e70f54a..9fc3d552a 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -397,16 +397,18 @@ options. ### Options * **--global (-g):** Operate on the global config file located at -`$COMPOSER_HOME/config.json` by default. Without this option, this command -affects the local composer.json file or a file specified by `--file`. + `$COMPOSER_HOME/config.json` by default. Without this option, this command + affects the local composer.json file or a file specified by `--file`. * **--editor (-e):** Open the local composer.json file using in a text editor as -defined by the `EDITOR` env variable. With the `--global` option, this opens -the global config file. + defined by the `EDITOR` env variable. With the `--global` option, this opens + the global config file. * **--unset:** Remove the configuration element named by `setting-key`. * **--list (-l):** Show the list of current config variables. With the `--global` - option this lists the global configuration only. + option this lists the global configuration only. * **--file="..." (-f):** Operate on a specific file instead of composer.json. Note - that this cannot be used in conjunction with the `--global` option. + that this cannot be used in conjunction with the `--global` option. +* **--absolute:** Returns absolute paths when fetching *-dir config values + instead of relative. ### Modifying Repositories diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index a08a6f4a6..832571b3f 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -57,6 +57,7 @@ class ConfigCommand extends Command new InputOption('unset', null, InputOption::VALUE_NONE, 'Unset the given setting-key'), new InputOption('list', 'l', InputOption::VALUE_NONE, 'List configuration settings'), new InputOption('file', 'f', InputOption::VALUE_REQUIRED, 'If you want to choose a different composer.json or config.json', 'composer.json'), + new InputOption('absolute', null, InputOption::VALUE_NONE, 'Returns absolute paths when fetching *-dir config values instead of relative'), new InputArgument('setting-key', null, 'Setting key'), new InputArgument('setting-value', InputArgument::IS_ARRAY, 'Setting value'), )) @@ -218,7 +219,7 @@ EOT $value = $data; } elseif (isset($data['config'][$settingKey])) { - $value = $data['config'][$settingKey]; + $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS); } else { throw new \RuntimeException($settingKey.' is not defined'); } diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 4bb2a06c1..f95b30177 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -19,6 +19,8 @@ use Composer\Config\ConfigSourceInterface; */ class Config { + const RELATIVE_PATHS = 1; + public static $defaultConfig = array( 'process-timeout' => 300, 'use-include-path' => false, @@ -153,7 +155,7 @@ class Config * @throws \RuntimeException * @return mixed */ - public function get($key) + public function get($key, $flags = 0) { switch ($key) { case 'vendor-dir': @@ -169,7 +171,7 @@ class Config $val = rtrim($this->process($this->getComposerEnv($env) ?: $this->config[$key]), '/\\'); $val = preg_replace('#^(\$HOME|~)(/|$)#', rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\') . '/', $val); - return $this->realpath($val); + return ($flags & self::RELATIVE_PATHS == 1) ? $val : $this->realpath($val); case 'cache-ttl': return (int) $this->config[$key];