Lighthouse: CSV output does not print to stdout by default

Created on 16 Apr 2019  ·  11Comments  ·  Source: GoogleChrome/lighthouse

When I use the options --output=json in Lighthouse the JSON is simply output on the command line. A file is not produced.

The documentations suggests it should work though.

bug

All 11 comments

This is the intended behavior for easier programmatic usage. The docs of the CLI clarify this a bit more.

image

If you want it to output to a file you can use --output-path, request multiple output types, or pipe stdout to a file.

Would you mind linking to us the documentation that suggests it will output to a file so we can update it?

Thank you for the quick response.

My apologies, I assumed all 3 options were equal. If the default for CSV and JSON both is stdout,why does adding --output CSV produces a CSV file.

Sorry if my question is silyl.

Oh not silly! That would be a bug thanks for raising!

Just to throw my 2 cents in. Why does it go to stdout by default? Why not make a file? When I use --json I really want a file, not stdout, esp. since the report is too long to copy now I have to pipe it to a file anyway.

The original rationale is that it makes sense to put programmatic things on stdout to do with whatever you like and the only reason HTML isn't stdout by default was because it just makes no sense to try to programmatically consume it.

We don't eliminate any functionality by making it all file by default though since someone can always --output-path=stdout so I'm open to nuking stdout default 🤷‍♂️

yeah, I think --output-path came second and LH originally saved to file or printed to stdout just based on --output. I believe we discussed making everything write to file by default regardless of output format at some point (maybe when we added --output-path? or were changing something related), but it seemed good to still print to stdout for piping so we kept this slightly awkward thing.

I think the argument was that when using LH as a CLI tool it should act like a CLI tool...but that was back when --output=json was the default. When we switched to html as the default (which is saved to file), it meant you had to add at least one flag to get LH to print to stdout, so that argument doesn't really apply that well anymore.

I'd also be fine with changing it since we have the --output-path=stdout escape hatch, the question is how many existing CI/monitoring pipelines will we be breaking in the process, making people have to look up how to print to stdout for the benefit of simplifying a thing we basically never get questions about (this one excluded :). It is going to be a major version bump, but is it worth it?

(re: CSV, though, we should definitely change either the readme to match reality or reality to match the readme)

but that was back when --output=json was the default

Or even when pretty was the default 😄

Or even when pretty was the default 😄

so pretty!

Screen Shot 2016-09-28 at 15 26 35

I don't think we reached a final conclusion but it'd be nice to get whatever we decide in for 5.0.

Options

  1. Fix the help text to say JSON is the only one that defaults to stdout, no functionality change.
  2. Fix the CSV default output to stdout, make the functionality do what we currently says it does.
  3. Change the default output of JSON to a file to match the others and update the docs accordingly, fairly significant breaking change for everyone using the CLI for JSON output.

I think I vote number 1 since this has so rarely come up and breaking doesn't seem worth it.

option 3 would mark a descent into madness. I have no opinion on the others.

Was this page helpful?
0 / 5 - 0 ratings