How do you return json and specify exit code? #1270
-
We're adding JSON support to our CLI. This requires us to return data from commands. I'm struggling in a few places to reconcile how that squares with exiting the process with non-zero codes. Can anyone provide some guidance on this pattern? if (forceSafe) {
this.logSuccess('Breaking changes were expected (forced)');
return this.successData({
data: {
checkType: 'registry',
breakingChanges: true,
warnings: toWaring(result.schemaCheck.warnings),
changes: toChange(result.schemaCheck.changes),
url: result.schemaCheck?.schemaCheck?.webUrl ?? null,
},
});
}
// TODO integrate return JSON with exit 1
this.exit(1);
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I'm currently exploring creating a subclass of ExitError that would output given data as json. |
Beta Was this translation helpful? Give feedback.
-
An even simpler solution my be just |
Beta Was this translation helpful? Give feedback.
-
If you want to modify the JSON that's returned when the command errors (or you call |
Beta Was this translation helpful? Give feedback.
-
I would like a way to modify the exit code without using |
Beta Was this translation helpful? Give feedback.
you can use
process.exitCode = 9999
and oclif should respect that up when exiting the command