updateFile function

Future<void> updateFile(
  1. String file,
  2. UpdateRule rule, {
  3. String operation = '',
  4. int expectedMatchCount = 0,
})

Implementation

Future<void> updateFile(String file, UpdateRule rule,
    {String operation = '', int expectedMatchCount = 0}) async {
  try {
    final matches = await FileUpdater.updateFile(File(file), rule);
    final matchCount = matches.length;

    debug(
        '$operation is updated on $file, total changes: $matchCount, lines: [${matches.join(',')}]');
    if (expectedMatchCount != matchCount) {
      error('$operation is not updated as expected, please repair the $file');
    }
  } on InvalidFormatException catch (e) {
    error(
        'the $operation value in the ${argResults[fileOption]} file is not valid! RegExp: ${e.message}, $file');
  }
  return Future.delayed(bufferDuration);
}