jsonResult method
Prints the result of the command in the standard output
as a single JSON object and returns the exitCode.
Should be called only if isJsonFormat is true.
Common fields of the envelope are filled here, so they are the same
for every command; data is a command specific payload.
Implementation
@protected
int jsonResult({
required int exitCode,
String? summary,
Map<String, dynamic> data = const {},
}) {
print.result(jsonEncode(<String, dynamic>{
'alex': packageVersion,
'command': fullName,
'ok': exitCode == 0,
'exitCode': exitCode,
if (summary != null) 'summary': summary,
...data,
}));
_isResultPrinted = true;
return exitCode;
}