From 91b7b0ff3bfa85b784a0aa173a66254421644c1a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Mar 2023 11:07:57 +0100 Subject: [PATCH] Fixed querying of default config values, and fix source display for them, and fix bools to show as bools, fixes #11302 --- src/Composer/Command/ConfigCommand.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index d7f4ad78a..3d5fb11d3 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -274,8 +274,21 @@ EOT // show the value if no value is provided if ([] === $input->getArgument('setting-value') && !$input->getOption('unset')) { $properties = self::CONFIGURABLE_PACKAGE_PROPERTIES; + $propertiesDefaults = [ + 'type' => 'library', + 'description' => '', + 'homepage' => '', + 'minimum-stability' => 'stable', + 'prefer-stable' => false, + 'keywords' => [], + 'license' => [], + 'suggest' => [], + 'extra' => [], + ]; $rawData = $this->configFile->read(); $data = $this->config->all(); + $source = $this->config->getSourceOfValue($settingKey); + if (Preg::isMatch('/^repos?(?:itories)?(?:\.(.+))?/', $settingKey, $matches)) { if (!isset($matches[1]) || $matches[1] === '') { $value = $data['repositories'] ?? []; @@ -313,17 +326,21 @@ EOT $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS); } elseif (isset($rawData[$settingKey]) && in_array($settingKey, $properties, true)) { $value = $rawData[$settingKey]; + $source = $this->configFile->getPath(); + } elseif (isset($propertiesDefaults[$settingKey])) { + $value = $propertiesDefaults[$settingKey]; + $source = 'defaults'; } else { throw new \RuntimeException($settingKey.' is not defined'); } - if (is_array($value)) { + if (is_array($value) || is_bool($value)) { $value = JsonFile::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } $sourceOfConfigValue = ''; if ($input->getOption('source')) { - $sourceOfConfigValue = ' (' . $this->config->getSourceOfValue($settingKey) . ')'; + $sourceOfConfigValue = ' (' . $source . ')'; } $this->getIO()->write($value . $sourceOfConfigValue, true, IOInterface::QUIET);