Explorar el Código

Make config command list all values in the config (aggregated defaults + global [+ local])

Jordi Boggiano hace 13 años
padre
commit
111c42b8fb
Se han modificado 2 ficheros con 36 adiciones y 5 borrados
  1. 24 5
      src/Composer/Command/ConfigCommand.php
  2. 12 0
      src/Composer/Config.php

+ 24 - 5
src/Composer/Command/ConfigCommand.php

@@ -27,6 +27,11 @@ use Composer\Json\JsonFile;
  */
 class ConfigCommand extends Command
 {
+    /**
+     * @var Config
+     */
+    protected $config;
+
     /**
      * @var Composer\Json\JsonFile
      */
@@ -97,10 +102,12 @@ EOT
             throw new \RuntimeException('--file and --global can not be combined');
         }
 
+        $this->config = Factory::createConfig();
+
         // Get the local composer.json, global config.json, or if the user
         // passed in a file to use
         $configFile = $input->getOption('global')
-            ? (Factory::createConfig()->get('home') . '/config.json')
+            ? ($this->config->get('home') . '/config.json')
             : $input->getOption('file');
 
         $this->configFile = new JsonFile($configFile);
@@ -144,9 +151,13 @@ EOT
             return 0;
         }
 
+        if (!$input->getOption('global')) {
+            $this->config->merge($this->configFile->read());
+        }
+
         // List the configuration of the file settings
         if ($input->getOption('list')) {
-            $this->listConfiguration($this->configFile->read(), $output);
+            $this->listConfiguration($this->config->all(), $output);
 
             return 0;
         }
@@ -161,9 +172,9 @@ EOT
             throw new \RuntimeException('You can not combine a setting value with --unset');
         }
 
-        // list value
+        // show the value if no value is provided
         if (array() === $input->getArgument('setting-value') && !$input->getOption('unset')) {
-            $data = $this->configFile->read();
+            $data = $this->config->all();
             if (preg_match('/^repos?(?:itories)?(?:\.(.+))?/', $settingKey, $matches)) {
                 if (empty($matches[1])) {
                     $value = isset($data['repositories']) ? $data['repositories'] : array();
@@ -315,7 +326,7 @@ EOT
                 continue;
             }
 
-            if (is_array($value) && !is_numeric(key($value))) {
+            if (is_array($value) && (!is_numeric(key($value)) || ($key === 'repositories' && null === $k))) {
                 $k .= preg_replace('{^config\.}', '', $key . '.');
                 $this->listConfiguration($value, $output, $k);
 
@@ -330,9 +341,17 @@ EOT
             }
 
             if (is_array($value)) {
+                $value = array_map(function ($val) {
+                    return is_array($val) ? json_encode($val) : $val;
+                }, $value);
+
                 $value = '['.implode(', ', $value).']';
             }
 
+            if (is_bool($value)) {
+                $value = var_export($value, true);
+            }
+
             $output->writeln('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>');
         }
     }

+ 12 - 0
src/Composer/Config.php

@@ -150,6 +150,18 @@ class Config
         }
     }
 
+    public function all()
+    {
+        $all = array(
+            'repositories' => $this->getRepositories(),
+        );
+        foreach (array_keys($this->config) as $key) {
+            $all['config'][$key] = $this->get($key);
+        }
+
+        return $all;
+    }
+
     /**
      * Checks whether a setting exists
      *