checklistFromFile function

Checklist checklistFromFile(
  1. String path
)

Lit un fichier de checklist. Son identifiant est le nom du fichier, sans extension ni suffixe de langue : smith-aspirant.fr.yaml donne smith-aspirant.

Implementation

Checklist checklistFromFile(String path) {
  final String content;
  try {
    content = File(path).readAsStringSync();
  } on FileSystemException catch (error) {
    throw GcheckException(ErrorCode.invalidInput, '$path: ${error.message}');
  }
  final stem = _stem(path);
  Checklist checklist;
  try {
    checklist = externalChecklist(stem, content);
  } on GcheckException catch (error) {
    throw GcheckException(error.code, '$path: ${error.message}', error.path);
  }
  final suffix = '.${checklist.lang}';
  if (stem.endsWith(suffix)) {
    checklist = Checklist(
      id: stem.substring(0, stem.length - suffix.length),
      lang: checklist.lang,
      status: checklist.status,
      content: checklist.content,
    );
  }
  return checklist;
}