RunnableScript.fromMap constructor

RunnableScript.fromMap(
  1. Map<String, dynamic> map, {
  2. FileSystem? fileSystem,
})

Generate a runnable script from a normal map as defined in the config.

Implementation

factory RunnableScript.fromMap(
  Map<String, dynamic> map, {
  FileSystem? fileSystem,
}) {
  if (map['name'] == null && map.keys.length == 1) {
    map['name'] = map.keys.first;
    map['cmd'] = map.values.first;
  } else {
    map.addAll(map.cast<String, dynamic>());
    map['args'] = (map['args'] as List?)?.map((e) => e.toString()).toList();
    map['env'] = (map['env'] as Map?)?.cast<String, String>();
  }
  final name = map['name'] as String;
  final rawCmd = map['cmd'] as String;
  final cmd = rawCmd;
  final rawArgs = (map['args'] as List<String>?) ?? [];
  final description = map['description'] as String?;
  final displayCmd = map['display_cmd'] as bool? ?? true;
  final appendNewline = map['append_newline'] as bool? ?? false;
  // print('cmdArgs: $cmdArgs');

  try {
    return RunnableScript(
      name,
      cmd: cmd,
      args: List<String>.from(rawArgs),
      fileSystem: fileSystem,
      description: description,
      displayCmd: displayCmd,
      appendNewline: appendNewline,
    );
  } catch (e) {
    throw StateError(
        'Failed to parse script, arguments: $map, $fileSystem. Error: $e');
  }
}