-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,14 @@ export const builder = { | |
describe: "Set max-buffer(bytes) for Command execution", | ||
type: "number", | ||
requiresArg: true | ||
}, | ||
"json": { | ||
describe: dedent` | ||
Returns output as a machine-readable json object | ||
(Only for 'ls' and 'updated' commands) | ||
`, | ||
type: "boolean", | ||
default: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default is implicit for boolean options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
}; | ||
|
||
|
@@ -70,6 +78,11 @@ export default class Command { | |
log.pause(); | ||
log.heading = "lerna"; | ||
|
||
// Default to silent log level for JSON output | ||
if (flags.json) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't necessary, actually, as all logging is emitted to It's too bad I didn't write a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in ceb1fe0 |
||
log.level = "silent"; | ||
} | ||
|
||
if (flags.loglevel) { | ||
log.level = flags.loglevel; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,6 +353,45 @@ describe("UpdatedCommand", () => { | |
updatedCommand.runCommand(exitWithCode(1, done)); | ||
}); | ||
}); | ||
|
||
/** ========================================================================= | ||
* JSON Output | ||
* ======================================================================= */ | ||
|
||
describe("with --json", () => { | ||
let testDir; | ||
|
||
beforeEach(() => initFixture("UpdatedCommand/basic").then((dir) => { | ||
testDir = dir; | ||
})); | ||
|
||
it("should list changes as a json object", (done) => { | ||
setupGitChanges(testDir, [ | ||
"packages/package-2/random-file", | ||
]); | ||
|
||
const updatedCommand = new UpdatedCommand([], { | ||
json: true | ||
}, testDir); | ||
|
||
updatedCommand.runValidations(); | ||
updatedCommand.runPreparations(); | ||
|
||
updatedCommand.runCommand(exitWithCode(0, (err) => { | ||
if (err) return done.fail(err); | ||
try { | ||
const outputStr = consoleOutput(); | ||
expect(outputStr).toMatchSnapshot(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just skip straight to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 73f492a |
||
// Output should be a parseable string | ||
const jsonOutput = JSON.parse(outputStr); | ||
expect(jsonOutput).toMatchSnapshot(); | ||
done(); | ||
} catch (ex) { | ||
done.fail(ex); | ||
} | ||
})); | ||
}); | ||
}); | ||
}); | ||
|
||
// TODO: remove this when we _really_ remove support for SECRET_FLAG | ||
|
There was a problem hiding this comment.
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 intoLsCommand
andUpdatedCommand
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)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ceb1fe0