replace method

List<String> replace(
  1. Script script,
  2. ScriptsConfig config, {
  3. OptionalFlags? flags,
})

Implementation

List<String> replace(
  Script script,
  ScriptsConfig config, {
  OptionalFlags? flags,
}) {
  late final sipVariables = populate();
  Iterable<String> resolve(String command) {
    return replaceVariables(
      command,
      sipVariables: sipVariables,
      config: config,
      flags: flags,
    );
  }

  final commands = <String>[
    if (script.env?.command case final commands?)
      for (final command in commands) ...resolve(command),
  ];

  for (final command in script.commands) {
    for (final resolved in resolve(command)) {
      commands.add(resolved.trim());
    }
  }

  return commands.toList();
}