run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
final rest = argResults!.rest;
if (rest.length > 1) {
return _usageError('Expected at most one project path.');
}
final root = rest.isEmpty ? Directory.current.path : rest.single;
final outcome = await validator(root);
final report = outcome.report;
final exitCode = report.result == ValidationResult.passed
? ExitReporter.success
: ExitReporter.validationFailed;
final result = {...report.toJson(), 'violations': outcome.violations};
if (_json) {
out(
renderEnvelope(
command: 'validate',
ok: exitCode == 0,
exitCode: exitCode,
result: result,
error: exitCode == 0
? null
: {
'code': 'VALIDATION_FAILED',
'exitCode': exitCode,
'message': _failureMessage(report, outcome.violations),
'cause': {
'failedGate': _failedGate(report),
'violations': outcome.violations,
},
'missingDecisions': const [],
},
),
);
} else if (exitCode == 0) {
out('Validation passed: format, analyze, and test gates are green.');
} else {
diagnostics(_failureMessage(report, outcome.violations));
}
return exitCode;
}