Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Split output to stderr and stdout#1654

Merged
keradus merged 1 commit into
PHP-CS-Fixer:1.12from
SpacePossum:1_12_feature_stdout_stderr
Apr 15, 2016
Merged

Split output to stderr and stdout#1654
keradus merged 1 commit into
PHP-CS-Fixer:1.12from
SpacePossum:1_12_feature_stdout_stderr

Conversation

@SpacePossum
Copy link
Copy Markdown
Contributor

For more correct testing I need symfony/symfony#17255 to be resolved.

issue: #1579 (and others)

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

What about switching to SymfonyStyle ?
$io = new SymfonyStyle($input, $output);

ref symfony/symfony#15986

@GrahamCampbell
Copy link
Copy Markdown
Contributor

We'd have to raise our min console version.

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

Raising dep version for just raising it is pointless. but rising it for functionality is OK ;)

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

BTW, then you won't need to test if console printer works on our end, just rely on vendor code (and it's tests)

@SpacePossum
Copy link
Copy Markdown
Contributor Author

hmm even more work to be done in symfony/console... ;)

I don't like the current output construction, because if an output is given to a receiver/output writter it has to check if there is another output attached to it that is even more appropriate. This is causing code like this all over the place;
https://github.com/symfony/symfony/pull/15795/files#diff-425e56e3b866cb257f587805f7b2ee54R41
why isn't the error output passed to that method in the first place?
and why not set hasErrOutput on the OutputInterface that would at least remove the instance checks...?

anyway, SymfonyStyle::error still writes to stdout IIRC.. let me check the coming days :)

@SpacePossum SpacePossum changed the title Split output to stderr and stdout. [WIP] Split output to stderr and stdout. Jan 5, 2016
@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

why isn't the error output passed to that method in the first place?

For ensuring that if it is possible the stdErr is used.
If it would be added to method's prototype then it would break BC, and if not (last & nullable param) then nobody would pass it and stdErr would not be used, and it is not the goal. Bit ugliness for nice output out of the box without changing user code.

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

anyway, SymfonyStyle::error still writes to stdout IIRC.. let me check the coming days :)

yes, and changing it will fix symfony/symfony#15986 ;)

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

We'd have to raise our min console version.

To use SymfonyStyle we will need to bump to v2.7, which has raised PHP requirement:

-        "php": ">=5.3.3"
+        "php": ">=5.3.9"

I'm ok with that, since it bump only PATCH version

@GrahamCampbell
Copy link
Copy Markdown
Contributor

Maybe 2.x is a better place to make this change?

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 5, 2016

Could you justify that?

@SpacePossum
Copy link
Copy Markdown
Contributor Author

Could you justify that?

it would safe you the merge hell ;)

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 6, 2016

There should not be a lot of differences between 1.x and 2.x since the output of both should be the same, but it is fine for me.

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 6, 2016

What about creating our own Style on top of SymfonyStyle, so we could add more things there (like our progress) ?

@stof
Copy link
Copy Markdown
Contributor

stof commented Jan 6, 2016

SymfonyStyle is about formatting the output. Telling that some styles must go to stdout and some other styles go to stderr is wrong. This is misunderstanding the goal of stderr and stdout (naming them stderr and stdout does not help understand their goal either btw).
any progress reporting output should also go to stderr, not to stdout (it is not part of the output of the program, which would be piped to another program)

@keradus
Copy link
Copy Markdown
Member

keradus commented Jan 6, 2016

Yep, we want to push the progress to stderr.
@stof, then what about symfony/symfony#15986 ? Is it going to be the proposed way or the issue will be rejected ?

@keradus
Copy link
Copy Markdown
Member

keradus commented Feb 6, 2016

@SpacePossum I think we won't hear anything about this from Symfony soon.
Are we able to handle it on our side at low cost?

@SpacePossum
Copy link
Copy Markdown
Contributor Author

@SpacePossum I think we won't hear anything about this from Symfony soon.

Why do you think, all members are busy? I'll ping again, its been 10 days since my last proposal, hope I ping the right people ^-^
I could write a similar fix in the mean time for the fixer, but it would not be handy if my fix over at symfony gets turned down.

@keradus
Copy link
Copy Markdown
Member

keradus commented Mar 4, 2016

@SpacePossum , symfony/symfony#15794 has been merged. Would it help us?

@SpacePossum
Copy link
Copy Markdown
Contributor Author

@keradus that PR addresses some helpers we don't use ATM (and probably won't any time soon).
I got an answer on 15986 from Fabien that contains enough pointers to finish it, I hope to find some time this weekend to do so.

@SpacePossum
Copy link
Copy Markdown
Contributor Author

My PR to SF to get testing options for both stdout and stderr has been merged, however it has been done on 3.x line only. I would like to suggest to move on without it by adding a bit of a polyfill until the fixer requirements reach the 3.x line of packages of SF.
I would really like to wrap this one up to close the issues related to outputting to the wrong stream(s) making it harder than needed to integrate the fixer with other applications. I would like to suggest to rebase and rework this after #1824 has been done as the PRs will have some conflicts among each other. Ping @keradus for thoughts on this :)

@keradus
Copy link
Copy Markdown
Member

keradus commented Mar 22, 2016

fine for me

@keradus
Copy link
Copy Markdown
Member

keradus commented Mar 30, 2016

ping @SpacePossum

@SpacePossum
Copy link
Copy Markdown
Contributor Author

I think a wait out #1824 since it will cover the output format testing. This means the tests here can be removed and this PR can focus on the used output streams only. I'll work on this soon to get the test logic in place we are going to need though :)

@keradus
Copy link
Copy Markdown
Member

keradus commented Apr 9, 2016

#1824 is merged. please update


$fixEvent = $this->stopwatch->getEvent('fixFiles');
$output->writeln(sprintf('%s all files in %.3f seconds, %.3f MB memory used', $input->getOption('dry-run') ? 'Checked' : 'Fixed', $fixEvent->getDuration() / 1000, $fixEvent->getMemory() / 1024 / 1024));
$stdErr->writeln(sprintf('%s all files in %.3f seconds, %.3f MB memory used', $input->getOption('dry-run') ? 'Checked' : 'Fixed', $fixEvent->getDuration() / 1000, $fixEvent->getMemory() / 1024 / 1024));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems wrong to print information to stderr when it's not an error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is not, the naming of the streams is confusing. It is better, IMO, to send all kind of information to stdErr and only parsable formatted info to stdOut

@SpacePossum
Copy link
Copy Markdown
Contributor Author

Reworked, please note this PR is now for ^1.12 only.

@keradus
Copy link
Copy Markdown
Member

keradus commented Apr 13, 2016

you mean that non of those changes should be merged into 2.x, right?

@SpacePossum
Copy link
Copy Markdown
Contributor Author

you mean that non of those changes should be merged into 2.x, right?

indeed, it is all good on 2.x :)

@keradus
Copy link
Copy Markdown
Member

keradus commented Apr 13, 2016

Cool ;)

@keradus keradus added this to the v1.12 milestone Apr 13, 2016
@keradus keradus added the RTM Ready To Merge label Apr 13, 2016
@SpacePossum SpacePossum changed the title [WIP] Split output to stderr and stdout. [^1.12] Split output to stderr and stdout. Apr 13, 2016
@keradus keradus changed the title [^1.12] Split output to stderr and stdout. Split output to stderr and stdout Apr 15, 2016
@keradus keradus removed the RTM Ready To Merge label Apr 15, 2016
@keradus
Copy link
Copy Markdown
Member

keradus commented Apr 15, 2016

Thank you @SpacePossum.

@keradus keradus merged commit 880f58d into PHP-CS-Fixer:1.12 Apr 15, 2016
keradus added a commit that referenced this pull request Apr 15, 2016
This PR was merged into the 1.12 branch.

Discussion
----------

Split output to stderr and stdout

For more correct testing I need symfony/symfony#17255 to be resolved.

issue: #1579 (and others)

Commits
-------

880f58d Split output to stderr and stdout.
@SpacePossum SpacePossum deleted the 1_12_feature_stdout_stderr branch April 21, 2016 08:18
@TomasVotruba
Copy link
Copy Markdown

I'm writing post about CLI output styles PHP packages use and I Googled this is the 1 place in PHP CS Fixer that mentions SymfonyStyle.

It was declided due to min-requiremeent bump to Symfony 2.8.

Now the min. version is Symfony 3.2, so it's ready 👍

Just FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants