From 9392adef79bedd1feea7e3053d695850ef5707f1 Mon Sep 17 00:00:00 2001 From: Tehem Date: Tue, 28 Jul 2015 00:01:01 +0200 Subject: [PATCH 1/3] Fixes #4302 allow COMPOSER env with config statements (overrides --file) --- src/Composer/Command/ConfigCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index a833a5140..41e9e3766 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -139,7 +139,7 @@ EOT // passed in a file to use $configFile = $input->getOption('global') ? ($this->config->get('home') . '/config.json') - : $input->getOption('file'); + : (trim(getenv('COMPOSER')) ? trim(getenv('COMPOSER')) : $input->getOption('file')); // create global composer.json if this was invoked using `composer global config` if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) { From b35e7623549c2ef2dae65fc6d49b887722a9615e Mon Sep 17 00:00:00 2001 From: Thomas Marcon Date: Fri, 31 Jul 2015 12:00:00 +0200 Subject: [PATCH 2/3] Updated configFile parsing to first look into -f parameter, then COMPOSER environment variable, then default to composer.json --- src/Composer/Command/ConfigCommand.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 41e9e3766..f792f84bd 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -66,7 +66,7 @@ class ConfigCommand extends Command new InputOption('auth', 'a', InputOption::VALUE_NONE, 'Affect auth config file (only used for --editor)'), 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('file', 'f', InputOption::VALUE_REQUIRED, 'If you want to choose a different composer.json or config.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'), @@ -138,8 +138,12 @@ EOT // Get the local composer.json, global config.json, or if the user // passed in a file to use $configFile = $input->getOption('global') - ? ($this->config->get('home') . '/config.json') - : (trim(getenv('COMPOSER')) ? trim(getenv('COMPOSER')) : $input->getOption('file')); + ? ($this->config->get('home').'/config.json') + : ( + $input->getOption('file') + ? $input->getOption('file') + : (trim(getenv('COMPOSER')) ? trim(getenv('COMPOSER')) : 'composer.json') + ); // create global composer.json if this was invoked using `composer global config` if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) { From 9e592f19a1298f46b7222005634064c2e42a250b Mon Sep 17 00:00:00 2001 From: Tehem Date: Mon, 3 Aug 2015 23:36:05 +0200 Subject: [PATCH 3/3] Used shorthand version for ternary operator --- src/Composer/Command/ConfigCommand.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index f792f84bd..96c431655 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -138,12 +138,8 @@ EOT // Get the local composer.json, global config.json, or if the user // passed in a file to use $configFile = $input->getOption('global') - ? ($this->config->get('home').'/config.json') - : ( - $input->getOption('file') - ? $input->getOption('file') - : (trim(getenv('COMPOSER')) ? trim(getenv('COMPOSER')) : 'composer.json') - ); + ? ($this->config->get('home') . '/config.json') + : ($input->getOption('file') ?: (trim(getenv('COMPOSER')) ? trim(getenv('COMPOSER')) : 'composer.json')); // create global composer.json if this was invoked using `composer global config` if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) {