run method

  1. @override
Future<void> run()
override

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!;
  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,
    '--dangerfile',
    args['dangerfile'],
    '--passURLForDSL',
    if (isFailOnErrors) '--failOnErrors',
    '--process',
    '"$dangerProcessCommand"',
    ...(args['base'] != null ? ['--base', args['base']] : []),
    ...(args['staging'] ? ['--staging'] : []),
  ].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) {
    _logger.e(e.toString());
    exitCode = 1;
  }
}