Skip to content
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

Add json output to ls and updated commands #824

Merged
merged 3 commits into from May 21, 2017
Merged

Conversation

ricky
Copy link
Contributor

@ricky ricky commented May 19, 2017

Description

Adds a --json flag, which is currently used only by lerna ls and lerna updated to produce machine-readable output.

Motivation and Context

Inspired by the discussion in #686 and my own desire to not have our artisanally-crafted script be reliant on the plain text formatting of lerna updated moving forward.

How Has This Been Tested?

Manually via invocations of the command with and without the --json flag, as well as new test cases.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ricky
Copy link
Contributor Author

ricky commented May 19, 2017

Node 4 test failure(s) appear to be unrelated... 👀

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Looks good so far, thanks @ricky!

if (err) return done.fail(err);
try {
const outputStr = consoleOutput();
expect(outputStr).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just skip straight to the JSON.parse(consoleOutput()) snapshot, as we really shouldn't be testing whether or not JSON.stringify() is working correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 73f492a

src/Command.js Outdated
@@ -70,6 +78,11 @@ export default class Command {
log.pause();
log.heading = "lerna";

// Default to silent log level for JSON output
if (flags.json) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary, actually, as all logging is emitted to stderr and only the JSON string is emitted to stdout. When you pipe the output, it only includes stdout (unless you do fancy stdio redirects, of course).

It's too bad I didn't write a lerna ls integration test that could demonstrate this :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in ceb1fe0

src/Command.js Outdated
(Only for 'ls' and 'updated' commands)
`,
type: "boolean",
default: false
Copy link
Member

Choose a reason for hiding this comment

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

This default is implicit for boolean options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/Command.js Outdated
@@ -62,6 +62,14 @@ export const builder = {
describe: "Set max-buffer(bytes) for Command execution",
type: "number",
requiresArg: true
},
"json": {
describe: dedent`
Copy link
Member

Choose a reason for hiding this comment

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

Let's move the json option descriptor into LsCommand and UpdatedCommand directly. It's an acceptable amount of duplication to maintain the benefit of targeted, relevant --help output. The description could be shorter, like "Show information in JSON format". (when in doubt, i copy npm's docs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ceb1fe0

@evocateur
Copy link
Member

And yes, the node v4 failure was due to a timeout. That's unfortunate, and hopefully rare?

Copy link
Contributor Author

@ricky ricky left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback!

src/Command.js Outdated
@@ -62,6 +62,14 @@ export const builder = {
describe: "Set max-buffer(bytes) for Command execution",
type: "number",
requiresArg: true
},
"json": {
describe: dedent`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ceb1fe0

src/Command.js Outdated
(Only for 'ls' and 'updated' commands)
`,
type: "boolean",
default: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/Command.js Outdated
@@ -70,6 +78,11 @@ export default class Command {
log.pause();
log.heading = "lerna";

// Default to silent log level for JSON output
if (flags.json) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in ceb1fe0

if (err) return done.fail(err);
try {
const outputStr = consoleOutput();
expect(outputStr).toMatchSnapshot();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 73f492a

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@evocateur evocateur merged commit 1a8571c into lerna:master May 21, 2017
@ricky ricky deleted the json-flag branch May 22, 2017 10:01
treshugart pushed a commit to treshugart/lerna that referenced this pull request May 24, 2017
@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants