Skip to content

[Console] Ease writing to stderr using SymfonyStyle #20586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Nov 21, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15986
License MIT
Doc PR n/a

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch 8 times, most recently from 3aebb3a to e8f2aa4 Compare November 21, 2016 23:41
@fabpot
Copy link
Member

fabpot commented Nov 21, 2016

Can't be in 2.8, should be in master

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch from e8f2aa4 to dadbebe Compare November 22, 2016 10:00
@chalasr chalasr changed the base branch from 2.8 to master November 22, 2016 10:01
@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch 2 times, most recently from a57543c to 2848adc Compare November 22, 2016 10:02
@chalasr chalasr changed the title [FrameworkBundle] Use stderr when relevant in commands [Console] Ease writing to stderr using SymfonyStyle Nov 22, 2016
@chalasr
Copy link
Member Author

chalasr commented Nov 22, 2016

Changed the scope then, proposing SymfonyStyle::getErrorIo() to ease writing to stderr using styles (feature), and secondly made built-in commands using it when it's relevant. Let me know if it should be done in two PRs.

@nicolas-grekas
Copy link
Member

@chalasr you decide :)

@stof
Copy link
Member

stof commented Nov 25, 2016

Even adding a new method must be in master, as it is a new feature

return;
$this->listBundles($errorIo);
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
$errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the return is broken

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed in #20632

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please dismiss your review? As the change is no more in this PR

@chalasr
Copy link
Member Author

chalasr commented Nov 25, 2016

@stof It was about proposing the new method here and fixing the existing commands in another PR by creating the instance of SymfonyStyle in the commands themselves. see #20632


public function testGetErrorIo()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the InputInterface::class notation now that this PR targets master

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch from b2d7a1a to 293e627 Compare November 25, 2016 13:38
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
*
* @return self
*/
public function getErrorIo()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name looks weird to me as we don't use IO anywhere in the code IIRC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. getErrorStyle() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to getErrorStyle()

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch 2 times, most recently from 1adbc3e to ed656e2 Compare December 13, 2016 12:19
protected function getErrorOutput()
{
if (!$this->output instanceof ConsoleOutputInterface) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it throw instead?

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch 2 times, most recently from 3a02b96 to 43b7085 Compare January 6, 2017 15:00
protected function getErrorOutput()
{
if (!$this->output instanceof ConsoleOutputInterface) {
throw new LogicException(sprintf('The output must be an instance of %s for using getErrorOutput().', ConsoleOutputInterface::class));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning the regular output instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, updated

@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch 2 times, most recently from 552c419 to 207836f Compare January 6, 2017 16:44
@chalasr chalasr force-pushed the framework/stylized-commands-proper-output branch from 207836f to 5b0504c Compare January 6, 2017 18:34
@fabpot
Copy link
Member

fabpot commented Jan 6, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 5b0504c into symfony:master Jan 6, 2017
fabpot added a commit that referenced this pull request Jan 6, 2017
…halasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Console] Ease writing to stderr using SymfonyStyle

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15986
| License       | MIT
| Doc PR        | n/a

Commits
-------

5b0504c [Console] Ease writing to stderr using styles
@chalasr chalasr deleted the framework/stylized-commands-proper-output branch January 6, 2017 21:04
fabpot added a commit that referenced this pull request Feb 19, 2017
…output (chalasr, ogizanagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle] Make use of stderr for non reliable output

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Built-in commands should make use of the proper outputs.
As a feature on master, considering that people may actually rely on stdout and the fact commands have been changed a lot since 2.7, I think it's not worth doing this change on lower branches.

Please see also #20586 which adds a `SymfonyStyle::getErrorStyle()` shortcut for easily switching to stderr.

Commits
-------

7b262d8 [FrameworkBundle] Use getErrorStyle() when relevant
9a3a568 Use stderr for some other commands
1ee48bf [FrameworkBundle] Make use of stderr for non reliable output
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 28, 2017
…ing SymfonyStyle (chalasr, javiereguiluz)

This PR was merged into the master branch.

Discussion
----------

[Console] Document how to exclude messages from output using SymfonyStyle

This adds documentation for symfony/symfony#20586, any suggestion will be really welcomed.

Commits
-------

a5c5524 Minor fix
ff0ccde Reworded the description
31a2a44 Document how to exclude irrelevant messages from command output using SymfonyStyle
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants