process method

Future<String> process(
  1. String? input
)

Processes and substitutes variables in a string with their corresponding values.

This function replaces placeholders in the format ${{VAR_NAME}} or ${VAR_NAME} with the values of the corresponding variables from the variables map.

Parameters:

  • input - The input string containing placeholders (can be null)

Returns the string with placeholders replaced by their corresponding values. If input is null, returns an empty string.

Implementation

Future<String> process(String? input) async {
  if (input == null) return "";

  input = await substituteCLIArguments(input);

  final pattern = RegExp(r'\$\{\{(\w+)\}\}|\$\{(\w+)\}');
  input = input.replaceAllMapped(pattern, (match) {
    final varName = match.group(1) ?? match.group(2); // capture either style
    final value = variables[varName?.trim()];

    if (value != null) {
      return value.toString();
    } else {
      return match.group(0)!;
    }
  });
  return input;
}