getExecBlock function

Map<String, List<String>> getExecBlock(
  1. Config config,
  2. Map<String, String> env, [
  3. List<String> blocks = const []
])

get commands input from yaml

Implementation

Map<String, List<String>> getExecBlock(
  Config config,
  Map<String, String> env, [
  List<String> blocks = const [],
]) {
  final String os_ = config.optionalString('os') ?? '';
  if (!isOsMatched(os_)) throw UsageException('err: invalid os', '');

  final map = <String, List<String>>{}; // map blockname, cmds;
  if (blocks.isEmpty) blocks.add('commands');
  for (var blockName in blocks) {
    var cmds = config.optionalStringList(blockName);
    if (cmds == null || cmds.isEmpty) {
      throw UsageException('err: required $blockName list', '');
    }

    final subNames = PathAction.values.asNameMap().keys.toList();
    for (var cmd in cmds) {
      final undef = undefined(cmd, env);
      if (undef.isNotEmpty) {
        throw UsageException('err: undef $undef, $cmd', '');
      }
      if (!isSubCmd(cmd, subNames)) {
        throw UsageException('err: subcmd $cmd', '');
      }
    }

    map[blockName] = cmds;
  }

  return map;
}