run method

  1. @override
Future run(
  1. Iterable<String> args
)
override

Parses args and invokes Command.run on the chosen command.

This always returns a Future in case the command is asynchronous. The Future will throw a UsageException if args was invalid.

Implementation

@override
Future run(Iterable<String> args) async {
  final results = parse(args);

  final String? preset = results.wasParsed(CliHelper.presetOption)
      ? results[CliHelper.presetOption]
      : null;

  String? from, to;

  if (preset != null) {
    final env = Platform.environment;
    switch (preset.toLowerCase()) {
      case 'gitlab':
        from = env['CI_MERGE_REQUEST_SOURCE_BRANCH_NAME'];
        to = env['CI_MERGE_REQUEST_TARGET_BRANCH_NAME'];
        break;

      default:
        from = results.parsed(CliHelper.fromOption);
        to = results.parsed(CliHelper.toOption);
        break;
    }
  }

  if (from != null && to != null) {
    final projectDir = CliHelper.projectDir(
      results[CliHelper.projectDirOption],
    );

    if (await CliHelper.existConfig(projectDir)) {
      final constraints = await CliHelper.loadConstraints(projectDir);

      for (final constraint in constraints) {
        if (constraint.resolve(from: from, to: to)) {
          exit(0);
        }
      }
      print('Access denied');
      exit(1);
    }
  }

  super.run(args);
}