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

main
Jordi Boggiano 10 years ago
parent 331bda235c
commit c54d6f93e3

@ -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

@ -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');
}

@ -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];

Loading…
Cancel
Save