MatrixToolOptions.parse constructor

MatrixToolOptions.parse(
  1. List<String> arguments
)

Takes the options out of arguments, the arguments of a matrix tool; the others stay, with those after the directory, which may be options of smf create.

Implementation

factory MatrixToolOptions.parse(List<String> arguments) {
  final (:rest, :flags, :values, :problems) = _leadingOptionsOf(arguments);
  final combinations = switch (values[_combinationsOption]) {
    final value? => EveryModuleCombinations.parse(value),
    null => EveryModuleCombinations.pairwise,
  };
  if (combinations == null) {
    problems.add(
      '--combinations takes pairwise, 3-wise or all, not '
      '${values[_combinationsOption]}.',
    );
  }
  final shard = switch (values[_shardOption]) {
    final value? => MatrixShard.parse(value),
    null => null,
  };
  if (values[_shardOption] case final value? when shard == null) {
    problems.add(
      '--shard takes <index>/<count>, such as 1/2, with an index from 1 to '
      'the count, not $value.',
    );
  }
  problems.addAll(_misusesOf(flags, values));
  final app = values[_appOption];
  return MatrixToolOptions._(
    rest,
    app != null
        ? NamedEveryModuleApp(app)
        : combinations ?? EveryModuleCombinations.pairwise,
    shard,
    problems.isEmpty ? null : problems.join(' '),
  );
}