Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a1b3df8
[Console] Better error handling when misuse of `ArgvInput` with arrays
symfonyaml Apr 12, 2024
aaef070
bug #54576 [Console] Better error handling when misuse of `ArgvInput`…
fabpot Jun 3, 2024
d4f6891
Prefix all sprintf() calls
derrabus Jun 20, 2024
f63a2ee
chore: CS fixes
keradus Jun 16, 2024
5ed7b6c
Add return type to __toString() methods
oliverquynh Jun 28, 2024
b71a095
Merge branch '7.1' into 7.2
nicolas-grekas Jun 28, 2024
d36a5fe
Update .gitattributes
fabpot Jul 6, 2024
22e3436
[Console] Remove a redundant check in `ErrorListener`
oliverquynh Jul 18, 2024
f807c53
Replace `TestCase::assertTrue(true)` with `TestCase::expectNotToPerfo…
alexandre-daubois Jul 22, 2024
43b48b2
Use CPP where possible
alexandre-daubois Jul 22, 2024
2bac616
Merge branch '7.1' into 7.2
xabbuh Jul 24, 2024
21e08e0
minor #57795 Use CPP where possible (alexandre-daubois)
fabpot Jul 25, 2024
2d8cffd
Merge branch '7.1' into 7.2
nicolas-grekas Jul 26, 2024
8b3ee1c
[Cache][Config][Console][DependencyInjection][FrameworkBundle] Remove…
alexandre-daubois Jul 19, 2024
b54fbe5
Create devcontainer.json
Jul 26, 2024
d48400b
Remove unused code and unnecessary `else` branches
alexandre-daubois Jul 31, 2024
7d6b78e
Code style change in `@PER-CS2.0` affecting `@Symfony` (parentheses f…
bonroyage Aug 1, 2024
a228c54
minor #57901 Code style change in ``@PER`-CS2.0` affecting ``@Symfony…
derrabus Aug 6, 2024
2204ca3
Merge branch '7.1' into 7.2
xabbuh Aug 12, 2024
7884dc7
[PhpUnitBridge][Console][VarDumper] Add support for `FORCE_COLOR` env…
serious-angel Jul 19, 2024
7e27871
feature #57777 [VarDumper] Add support for `FORCE_COLOR` environment …
nicolas-grekas Aug 13, 2024
3c43d7e
Merge branch '7.1' into 7.2
nicolas-grekas Aug 13, 2024
cc2dd55
Merge branch '7.1' into 7.2
chalasr Aug 15, 2024
ee7ee22
[Console][Process] Add `$verbosity` argument to `mustRun` helper method
willrowe Aug 23, 2024
07d683c
no longer use the internal TestFailure class
xabbuh Sep 5, 2024
4843e24
Merge branch '7.1' into 7.2
derrabus Sep 8, 2024
07792b2
Merge branch '7.1' into 7.2
derrabus Sep 20, 2024
e57e6e0
[Console] Add silent verbosity mode suppressing all output, including…
wouterj Sep 19, 2024
300899a
Fix `$this` calls to static ones when relevant
alexandre-daubois Sep 24, 2024
dde368a
Remove useless parent method calls in tests
alexandre-daubois Sep 24, 2024
a113dc3
Merge branch '7.1' into 7.2
nicolas-grekas Sep 25, 2024
96ca566
Merge branch '7.1' into 7.2
nicolas-grekas Sep 25, 2024
dbccd36
Remove unused imports
alexandre-daubois Sep 26, 2024
dfd8158
minor #58374 Remove useless parent method calls in tests (alexandre-d…
fabpot Sep 27, 2024
c8b5404
Merge branch '7.1' into 7.2
xabbuh Sep 28, 2024
e31f47c
Remove a few unnecessary full qualifier
alexandre-daubois Oct 1, 2024
6f86f8d
Add finished indicator to ProgressIndicator
LauLaman Jun 28, 2024
8453956
Various CS fix for consistency
alexandre-daubois Oct 3, 2024
270fd98
[Console] Use assertSame for input tests
theofidry Oct 4, 2024
721a55b
minor #58443 Various CS fix for consistency (alexandre-daubois)
fabpot Oct 6, 2024
b4f6757
feature #57576 [Console] Add finished indicator to `ProgressIndicator…
fabpot Oct 6, 2024
23a1a63
[Console] Add ability to schedule alarm signals and a `console.alarm`…
HypeMC Sep 17, 2024
de23257
CS: clean some whitespaces/indentation
keradus Oct 6, 2024
a97129d
Add `$seconds` to `keepalive` methods
valtzu Oct 13, 2024
8f6d3ec
Reduce common control flows
alexandre-daubois Oct 14, 2024
de74db6
Remove always true/false occurrences
alexandre-daubois Oct 18, 2024
c32691c
Don't use `die()` in PHPT `--SKIPIF--`
staabm Oct 27, 2024
3fda7e5
Merge branch '7.1' into 7.2
nicolas-grekas Nov 5, 2024
23c8aae
Merge branch '7.1' into 7.2
nicolas-grekas Nov 6, 2024
13189ef
Merge branch '7.1' into 7.2
xabbuh Dec 7, 2024
799445d
fix risky test that doesn't perform any assertions
xabbuh Dec 7, 2024
722fa7c
Merge branch '6.4' into 7.2
xabbuh Dec 9, 2024
fefcc18
[Console] Fix tests
chalasr Dec 11, 2024
759bdb4
Merge branch 'symfony:7.2' into patch-1
Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] Add silent verbosity mode suppressing all output, including…
… errors
  • Loading branch information
wouterj committed Sep 21, 2024
commit e57e6e0355bf231a6befd5d8ff2940308f0005eb
13 changes: 10 additions & 3 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@ protected function configureIO(InputInterface $input, OutputInterface $output):
}

switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
case -2:
$output->setVerbosity(OutputInterface::VERBOSITY_SILENT);
break;
case -1:
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
break;
Expand All @@ -930,7 +933,10 @@ protected function configureIO(InputInterface $input, OutputInterface $output):
break;
}

if (true === $input->hasParameterOption(['--quiet', '-q'], true)) {
if (true === $input->hasParameterOption(['--silent'], true)) {
$output->setVerbosity(OutputInterface::VERBOSITY_SILENT);
$shellVerbosity = -2;
} elseif (true === $input->hasParameterOption(['--quiet', '-q'], true)) {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
$shellVerbosity = -1;
} else {
Expand All @@ -946,7 +952,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output):
}
}

if (-1 === $shellVerbosity) {
if (0 > $shellVerbosity) {
$input->setInteractive(false);
}

Expand Down Expand Up @@ -1082,7 +1088,8 @@ protected function getDefaultInputDefinition(): InputDefinition
return new InputDefinition([
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
new InputOption('--silent', null, InputOption::VALUE_NONE, 'Do not output any message'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Only errors are displayed. All other output is suppressed'),
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
new InputOption('--ansi', '', InputOption::VALUE_NEGATABLE, 'Force (or disable --no-ansi) ANSI output', null),
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG

* Add support for `FORCE_COLOR` environment variable
* Add `verbosity` argument to `mustRun` process helper method
* [BC BREAK] Add silent verbosity (`--silent`/`SHELL_VERBOSITY=-2`) to suppress all output, including errors
* Add `OutputInterface::isSilent()`, `Output::isSilent()`, `OutputStyle::isSilent()` methods

7.1
---
Expand Down
1 change: 1 addition & 0 deletions Descriptor/ReStructuredTextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private function getNonDefaultOptions(InputDefinition $definition): array
{
$globalOptions = [
'help',
'silent',
'quiet',
'verbose',
'version',
Expand Down
9 changes: 7 additions & 2 deletions Output/NullOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ public function setVerbosity(int $level): void

public function getVerbosity(): int
{
return self::VERBOSITY_QUIET;
return self::VERBOSITY_SILENT;
}

public function isQuiet(): bool
public function isSilent(): bool
{
return true;
}

public function isQuiet(): bool
{
return false;
}

public function isVerbose(): bool
{
return false;
Expand Down
10 changes: 8 additions & 2 deletions Output/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
/**
* Base class for output classes.
*
* There are five levels of verbosity:
* There are six levels of verbosity:
*
* * normal: no option passed (normal output)
* * verbose: -v (more output)
* * very verbose: -vv (highly extended output)
* * debug: -vvv (all debug output)
* * quiet: -q (no output)
* * quiet: -q (only output errors)
* * silent: --silent (no output)
*
* @author Fabien Potencier <[email protected]>
*/
Expand Down Expand Up @@ -74,6 +75,11 @@ public function getVerbosity(): int
return $this->verbosity;
}

public function isSilent(): bool
{
return self::VERBOSITY_SILENT === $this->verbosity;
}

public function isQuiet(): bool
{
return self::VERBOSITY_QUIET === $this->verbosity;
Expand Down
3 changes: 3 additions & 0 deletions Output/OutputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* OutputInterface is the interface implemented by all Output classes.
*
* @author Fabien Potencier <[email protected]>
*
* @method bool isSilent()
*/
interface OutputInterface
{
public const VERBOSITY_SILENT = 8;
public const VERBOSITY_QUIET = 16;
public const VERBOSITY_NORMAL = 32;
public const VERBOSITY_VERBOSE = 64;
Expand Down
6 changes: 6 additions & 0 deletions Style/OutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public function getFormatter(): OutputFormatterInterface
return $this->output->getFormatter();
}

public function isSilent(): bool
{
// @deprecated since Symfony 7.2, change to $this->output->isSilent() in 8.0
return method_exists($this->output, 'isSilent') ? $this->output->isSilent() : self::VERBOSITY_SILENT === $this->output->getVerbosity();
}

public function isQuiet(): bool
{
return $this->output->isQuiet();
Expand Down
5 changes: 4 additions & 1 deletion Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,15 @@ public function testRenderException()
putenv('COLUMNS=120');
$tester = new ApplicationTester($application);

$tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);
$tester->run(['command' => 'foo'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_QUIET, 'capture_stderr_separately' => true]);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exception');

$tester->run(['command' => 'foo'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE, 'capture_stderr_separately' => true]);
$this->assertStringContainsString('Exception trace', $tester->getErrorOutput(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');

$tester->run(['command' => 'foo'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_SILENT, 'capture_stderr_separately' => true]);
$this->assertSame('', $tester->getErrorOutput(true), '->renderException() renders nothing in SILENT verbosity');

$tester->run(['command' => 'list', '--foo' => true], ['decorated' => false, 'capture_stderr_separately' => true]);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getErrorOutput(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');

Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/CompleteCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti

public static function provideCompleteCommandInputDefinitionInputs()
{
yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--silent', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']];
yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--silent', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']];
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/Command/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function testExecuteListsCommandsOrder()

Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
--silent Do not output any message
-q, --quiet Only errors are displayed. All other output is suppressed
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
Expand Down
44 changes: 40 additions & 4 deletions Tests/Fixtures/application_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@
"description": "Display help for the given command. When no command is given display help for the <info>list</info> command",
"default": false
},
"silent": {
"name": "--silent",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"default": false
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"description": "Only errors are displayed. All other output is suppressed",
"default": false
},
"verbose": {
Expand Down Expand Up @@ -150,13 +159,22 @@
"description": "Display help for the given command. When no command is given display help for the <info>list</info> command",
"default": false
},
"silent": {
"name": "--silent",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"default": false
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"description": "Only errors are displayed. All other output is suppressed",
"default": false
},
"verbose": {
Expand Down Expand Up @@ -262,13 +280,22 @@
"description": "Display help for the given command. When no command is given display help for the <info>list</info> command",
"default": false
},
"silent": {
"name": "--silent",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"default": false
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"description": "Only errors are displayed. All other output is suppressed",
"default": false
},
"verbose": {
Expand Down Expand Up @@ -365,13 +392,22 @@
"description": "Display help for the given command. When no command is given display help for the <info>list</info> command",
"default": false
},
"silent": {
"name": "--silent",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"default": false
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"description": "Only errors are displayed. All other output is suppressed",
"default": false
},
"verbose": {
Expand Down
36 changes: 33 additions & 3 deletions Tests/Fixtures/application_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Display help for the given command. When no command is given display help for th
* Is negatable: no
* Default: `false`

#### `--quiet|-q`
#### `--silent`

Do not output any message

Expand All @@ -58,6 +58,16 @@ Do not output any message
* Is negatable: no
* Default: `false`

#### `--quiet|-q`

Only errors are displayed. All other output is suppressed

* Accept value: no
* Is value required: no
* Is multiple: no
* Is negatable: no
* Default: `false`

#### `--verbose|-v|-vv|-vvv`

Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Expand Down Expand Up @@ -159,7 +169,7 @@ Display help for the given command. When no command is given display help for th
* Is negatable: no
* Default: `false`

#### `--quiet|-q`
#### `--silent`

Do not output any message

Expand All @@ -169,6 +179,16 @@ Do not output any message
* Is negatable: no
* Default: `false`

#### `--quiet|-q`

Only errors are displayed. All other output is suppressed

* Accept value: no
* Is value required: no
* Is multiple: no
* Is negatable: no
* Default: `false`

#### `--verbose|-v|-vv|-vvv`

Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Expand Down Expand Up @@ -286,7 +306,7 @@ Display help for the given command. When no command is given display help for th
* Is negatable: no
* Default: `false`

#### `--quiet|-q`
#### `--silent`

Do not output any message

Expand All @@ -296,6 +316,16 @@ Do not output any message
* Is negatable: no
* Default: `false`

#### `--quiet|-q`

Only errors are displayed. All other output is suppressed

* Accept value: no
* Is value required: no
* Is multiple: no
* Is negatable: no
* Default: `false`

#### `--verbose|-v|-vv|-vvv`

Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Expand Down
3 changes: 2 additions & 1 deletion Tests/Fixtures/application_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Console Tool

<comment>Options:</comment>
<info>-h, --help</info> Display help for the given command. When no command is given display help for the <info>list</info> command
<info>-q, --quiet</info> Do not output any message
<info> --silent</info> Do not output any message
<info>-q, --quiet</info> Only errors are displayed. All other output is suppressed
<info>-V, --version</info> Display this application version
<info> --ansi|--no-ansi</info> Force (or disable --no-ansi) ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
Expand Down
Loading