using method

void using(
  1. File file, {
  2. PlaceholderContract? placeholder,
})

Implementation

void using(File file, {PlaceholderContract? placeholder}) {
  final String stringContent = file.readAsStringSync();
  final content = switch (placeholder) {
    PlaceholderContract(:final apply) => apply(stringContent),
    _ => stringContent
  };

  final payload = switch (file.path) {
    final String path when path.contains('.json') => json.decode(content),
    final String path when path.contains('.yaml') =>
      (loadYaml(content) as YamlMap).toMap(),
    final String path when path.contains('.yml') =>
      (loadYaml(content) as YamlMap).toMap(),
    _ => throw Exception('File type not supported')
  };

  _declareCommand(payload);
  _declareGroups(payload);
  _declareSubCommands(payload);
}