run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<void> run() async {
final args = argResults!;
var url = '';
if (name == 'pr') {
if (args.rest.isEmpty) {
throw 'Please provide pull request url';
} else {
url = args.rest[0];
}
}
final isDebug = args.wasParsed('debug');
final isVerbose = args.wasParsed('verbose');
final isFailOnErrors = args.wasParsed('failOnErrors');
final useColors = (Platform.environment['TERM'] ?? '').contains('xterm');
if (isVerbose) {
Fimber.plantTree(DebugTree(useColors: useColors));
} else {
Fimber.plantTree(
DebugTree(useColors: useColors, logLevels: ['I', 'W', 'E']));
}
final dangerFilePath = dangerUtil.getDangerFile(args);
final metaData = await dangerUtil.getDangerJSMetaData(args);
final dangerProcessCommand = <String>[
'dart',
'run',
...isDebug
? [
'--observe=8181',
'--no-pause-isolates-on-exit',
]
: [],
(dangerUtil.getScriptFilePath()),
'process',
'--dangerfile',
dangerFilePath,
...isDebug ? ['--debug'] : [],
].join(' ');
final dangerJSCommand = <String>[
metaData.executable,
name,
...(url.isNotEmpty ? [url] : []),
if (isFailOnErrors) '--failOnErrors',
'--dangerfile',
args['dangerfile'],
'--passURLForDSL',
'--process',
"'$dangerProcessCommand'"
].join(' ');
try {
_logger.d('Arguments [$dangerJSCommand]');
_logger.d('Run shell');
final result = await dangerUtil.execShellCommand(dangerJSCommand,
isVerbose: isVerbose);
_logger.d('Run Completed');
exitCode = result.last.exitCode;
} catch (e) {
if (e is Error) {
_logger.e(e.toString(), ex: e, stacktrace: e.stackTrace);
} else {
_logger.e(e.toString(), ex: e);
}
exitCode = 1;
}
}