expandEnvironment function
Replaces ${NAME} with the value of the environment variable NAME.
Implementation
String expandEnvironment(String value, Map<String, String> environment) =>
value.replaceAllMapped(RegExp(r'\$\{(\w+)\}'), (match) {
final name = match[1]!;
final resolved = environment[name];
if (resolved == null) {
throw StateError('Environment variable $name is not set.');
}
return resolved;
});