Skip to content

Commit 26ebc65

Browse files
committed
Do not show title if explicitly configured to --format=yaml or --format=json
1 parent 974bbdb commit 26ebc65

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ protected function configure(): void
4949
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
5050
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
5151
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
52-
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'yaml' : 'json'),
53-
new InputOption('no-title', null, InputOption::VALUE_NONE, 'Does not output the title, useful when the output should be parsed using json or yaml.'),
52+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'txt' : 'json'),
5453
])
5554
->setHelp(<<<EOF
5655
The <info>%command.name%</info> command dumps the current configuration for an
@@ -98,14 +97,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9897

9998
$format = $input->getOption('format');
10099

101-
if ('yaml' === $format && !class_exists(Yaml::class)) {
102-
$errorIo->error('Setting the "format" option to "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
100+
if (\in_array($format, ['txt', 'yml'], true) && !class_exists(Yaml::class)) {
101+
$errorIo->error('Setting the "format" option to "txt" or "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
103102

104103
return 1;
105104
}
106105

107106
if (null === $path = $input->getArgument('path')) {
108-
if (!$input->getOption('no-title')) {
107+
if ('txt' === $input->getOption('format')) {
109108
$io->title(
110109
sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name))
111110
);
@@ -134,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134133
private function convertToFormat(mixed $config, string $format): string
135134
{
136135
return match ($format) {
137-
'yaml' => Yaml::dump($config, 10),
136+
'txt', 'yaml' => Yaml::dump($config, 10),
138137
'json' => json_encode($config, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE),
139138
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
140139
};
@@ -271,6 +270,6 @@ private static function buildPathsCompletion(array $paths, string $prefix = ''):
271270

272271
private function getAvailableFormatOptions(): array
273272
{
274-
return ['yaml', 'json'];
273+
return ['txt', 'yaml', 'json'];
275274
}
276275
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testDumpBundleOption(bool $debug)
9191
public function testDumpWithoutTitleIsValidJson(bool $debug)
9292
{
9393
$tester = $this->createCommandTester($debug);
94-
$ret = $tester->execute(['name' => 'TestBundle', '--format' => 'json', '--no-title' => true]);
94+
$ret = $tester->execute(['name' => 'TestBundle', '--format' => 'json']);
9595

9696
$this->assertSame(0, $ret, 'Returns 0 in case of success');
9797
$this->assertJson($tester->getDisplay());
@@ -106,7 +106,7 @@ public function testDumpWithUnsupportedFormat(bool $debug)
106106
$tester = $this->createCommandTester($debug);
107107

108108
$this->expectException(InvalidArgumentException::class);
109-
$this->expectExceptionMessage('Supported formats are "yaml", "json"');
109+
$this->expectExceptionMessage('Supported formats are "txt", "yaml", "json"');
110110

111111
$tester->execute([
112112
'name' => 'test',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy