run function Null safety

Future<void> run(
  1. dynamic args
)

Runs specified gherkin files with provided flags. This is left for backwards compatibility. args may be a list of filepaths.

Implementation

Future<void> run(args) async {
  var options = _parseArguments(args);

  // Use this to run with argument in IDE. Useful for debug.
  if (options.arguments.isEmpty) {
    var hardcodedArg = ['example/gherkin/test_feature.feature'];
    options = _parseArguments(hardcodedArg);
  }

  final debug = options["debug"];
  if (debug) {
    Logger.root.level = Level.FINE;
  } else {
    Logger.root.level = Level.INFO;
  }

  List<String>? runTags = [];
  if (options["tags"] != null) {
    runTags = options["tags"].split(",");
  }

  final featureFiles = options.rest;
  OguretsState state = OguretsState(ConsoleBuffer());
  state.runTags = runTags;
  await state.build();

  RunStatus runStatus = RunStatus(state.fmt);

  for (String filePath in featureFiles) {
    List<String> contents = await File(filePath).readAsLines();
    _Feature feature = await (GherkinParserTask(contents, filePath).execute()
        as FutureOr<_Feature>);
    FeatureStatus featureStatus = await feature.execute(state, debug: debug);
    if (featureStatus.failed) {
      runStatus.failedFeatures.add(featureStatus);
    } else if (featureStatus.skipped) {
      runStatus.skippedFeatures.add(featureStatus);
    } else {
      runStatus.passedFeatures.add(featureStatus);
    }
    state.fmt!.done(featureStatus);
  }

  state.fmt!.eof(runStatus);
}