Skip to content

Commit 2cebc67

Browse files
committed
fix: hide logo for JSON output modes
1 parent 1390eeb commit 2cebc67

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12-
- Show the DevTools ASCII logo by default on all top-level command executions, while adding a `--no-logo` global option that is automatically forwarded to internal DevTools subprocesses to avoid banner repetition in orchestrated command queues (#277)
12+
- Show the DevTools ASCII logo by default on all top-level command executions, while adding a `--no-logo` global option and automatically suppressing the banner for `--json` / `--pretty-json` invocations (including automatic forwarding of `--no-logo` to internal DevTools subprocesses) to avoid banner repetition in orchestrated command queues (#277)
1313

1414
### Added
1515

src/Console/DevTools.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ protected function getDefaultInputDefinition(): InputDefinition
139139
#[Override]
140140
public function doRun(InputInterface $input, OutputInterface $output): int
141141
{
142-
$noLogo = (bool) $input->getParameterOption('--no-logo', null, true);
142+
$noLogo = (bool) $input->getParameterOption('--no-logo', null, true)
143+
|| (bool) $input->hasParameterOption('--json', true)
144+
|| (bool) $input->hasParameterOption('--pretty-json', true);
143145

144146
if (! $noLogo) {
145147
$output->writeln(self::LOGO);

tests/Console/DevToolsTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use Symfony\Component\Console\Command\ListCommand;
6464
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
6565
use Symfony\Component\Console\Input\ArrayInput;
66+
use Symfony\Component\Console\Input\InputOption;
6667
use Symfony\Component\Console\Input\InputInterface;
6768
use Symfony\Component\Console\Output\OutputInterface;
6869
use Symfony\Component\Console\Output\BufferedOutput;
@@ -271,6 +272,96 @@ public function doRunWillNotRenderLogoWhenNoLogoOptionIsSet(): void
271272
self::assertStringNotContainsString('_____', $output->fetch());
272273
}
273274

275+
/**
276+
* @return void
277+
*/
278+
#[Test]
279+
public function doRunWillNotRenderLogoWhenJsonOptionIsProvided(): void
280+
{
281+
$command = new class extends Command {
282+
public function __construct()
283+
{
284+
parent::__construct('standards');
285+
}
286+
287+
protected function configure(): void
288+
{
289+
$this->addOption(name: 'json', mode: InputOption::VALUE_NONE, description: 'Emit structured JSON output.');
290+
$this->setCode(static fn(InputInterface $input, OutputInterface $output): int => Command::SUCCESS);
291+
}
292+
};
293+
294+
$this->commandLoader->has('standards')
295+
->willReturn(true)
296+
->shouldBeCalledOnce();
297+
$this->commandLoader->get('standards')
298+
->willReturn($command)
299+
->shouldBeCalledOnce();
300+
$input = new ArrayInput([
301+
'command' => 'standards',
302+
'--json' => true,
303+
]);
304+
305+
$output = new BufferedOutput();
306+
307+
$this->environment->get('FAST_FORWARD_AUTO_UPDATE', '')
308+
->willReturn('');
309+
$this->workingDirectorySwitcher->switchTo(null)
310+
->shouldBeCalledOnce();
311+
$this->versionCheckNotifier->notify($output)
312+
->shouldNotBeCalled();
313+
314+
$result = $this->invokeDoRun($input, $output);
315+
316+
self::assertSame(Command::SUCCESS, $result);
317+
self::assertStringNotContainsString('_____', $output->fetch());
318+
}
319+
320+
/**
321+
* @return void
322+
*/
323+
#[Test]
324+
public function doRunWillNotRenderLogoWhenPrettyJsonOptionIsProvided(): void
325+
{
326+
$command = new class extends Command {
327+
public function __construct()
328+
{
329+
parent::__construct('standards');
330+
}
331+
332+
protected function configure(): void
333+
{
334+
$this->addOption(name: 'pretty-json', mode: InputOption::VALUE_NONE, description: 'Emit pretty JSON output.');
335+
$this->setCode(static fn(InputInterface $input, OutputInterface $output): int => Command::SUCCESS);
336+
}
337+
};
338+
339+
$this->commandLoader->has('standards')
340+
->willReturn(true)
341+
->shouldBeCalledOnce();
342+
$this->commandLoader->get('standards')
343+
->willReturn($command)
344+
->shouldBeCalledOnce();
345+
$input = new ArrayInput([
346+
'command' => 'standards',
347+
'--pretty-json' => true,
348+
]);
349+
350+
$output = new BufferedOutput();
351+
352+
$this->environment->get('FAST_FORWARD_AUTO_UPDATE', '')
353+
->willReturn('');
354+
$this->workingDirectorySwitcher->switchTo(null)
355+
->shouldBeCalledOnce();
356+
$this->versionCheckNotifier->notify($output)
357+
->shouldNotBeCalled();
358+
359+
$result = $this->invokeDoRun($input, $output);
360+
361+
self::assertSame(Command::SUCCESS, $result);
362+
self::assertStringNotContainsString('_____', $output->fetch());
363+
}
364+
274365
/**
275366
* @return void
276367
*/

0 commit comments

Comments
 (0)