updateYearOnFile method

Future<void> updateYearOnFile(
  1. String? specificFile
)

Implementation

Future<void> updateYearOnFile(String? specificFile) async {
  final file = specificFile is String
      ? await _findLicenseFile(specificFile)
      : await _findDefaultLicenseFiles();
  final contents = await file.readAsString();
  if (!_yearIsUpdated(contents)) {
    final replacement = _replaceYear(contents);
    await file.writeAsString(replacement.content);
    printer.printSuccess(
      'Year on ${file.basename} file has been updated to "${replacement.yearPhrase}".',
    );
  } else {
    printer.println('Year on ${file.basename} file is already updated.');
  }
}