1
0
Fork 0

Add --absolute to resolve absolute paths in config command, otherwise set default back to relative

pull/3562/head
Jordi Boggiano 2014-12-16 14:28:51 +00:00
parent 331bda235c
commit c54d6f93e3
3 changed files with 14 additions and 9 deletions

View File

@ -397,16 +397,18 @@ options.
### Options ### Options
* **--global (-g):** Operate on the global config file located at * **--global (-g):** Operate on the global config file located at
`$COMPOSER_HOME/config.json` by default. Without this option, this command `$COMPOSER_HOME/config.json` by default. Without this option, this command
affects the local composer.json file or a file specified by `--file`. 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 * **--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 defined by the `EDITOR` env variable. With the `--global` option, this opens
the global config file. the global config file.
* **--unset:** Remove the configuration element named by `setting-key`. * **--unset:** Remove the configuration element named by `setting-key`.
* **--list (-l):** Show the list of current config variables. With the `--global` * **--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 * **--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 ### Modifying Repositories

View File

@ -57,6 +57,7 @@ class ConfigCommand extends Command
new InputOption('unset', null, InputOption::VALUE_NONE, 'Unset the given setting-key'), new InputOption('unset', null, InputOption::VALUE_NONE, 'Unset the given setting-key'),
new InputOption('list', 'l', InputOption::VALUE_NONE, 'List configuration settings'), 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('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-key', null, 'Setting key'),
new InputArgument('setting-value', InputArgument::IS_ARRAY, 'Setting value'), new InputArgument('setting-value', InputArgument::IS_ARRAY, 'Setting value'),
)) ))
@ -218,7 +219,7 @@ EOT
$value = $data; $value = $data;
} elseif (isset($data['config'][$settingKey])) { } elseif (isset($data['config'][$settingKey])) {
$value = $data['config'][$settingKey]; $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS);
} else { } else {
throw new \RuntimeException($settingKey.' is not defined'); throw new \RuntimeException($settingKey.' is not defined');
} }

View File

@ -19,6 +19,8 @@ use Composer\Config\ConfigSourceInterface;
*/ */
class Config class Config
{ {
const RELATIVE_PATHS = 1;
public static $defaultConfig = array( public static $defaultConfig = array(
'process-timeout' => 300, 'process-timeout' => 300,
'use-include-path' => false, 'use-include-path' => false,
@ -153,7 +155,7 @@ class Config
* @throws \RuntimeException * @throws \RuntimeException
* @return mixed * @return mixed
*/ */
public function get($key) public function get($key, $flags = 0)
{ {
switch ($key) { switch ($key) {
case 'vendor-dir': case 'vendor-dir':
@ -169,7 +171,7 @@ class Config
$val = rtrim($this->process($this->getComposerEnv($env) ?: $this->config[$key]), '/\\'); $val = rtrim($this->process($this->getComposerEnv($env) ?: $this->config[$key]), '/\\');
$val = preg_replace('#^(\$HOME|~)(/|$)#', rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\') . '/', $val); $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': case 'cache-ttl':
return (int) $this->config[$key]; return (int) $this->config[$key];