writeCommandsIndex function
End-to-end: scan + write. Returns the discovered command list so the caller can report what was registered.
Implementation
List<DiscoveredCommand> writeCommandsIndex(Directory commandsDir) {
final discovered = discoverCommandsInDir(commandsDir);
if (!commandsDir.existsSync()) {
commandsDir.createSync(recursive: true);
}
final indexFile = File(p.join(commandsDir.path, '_index.g.dart'));
indexFile.writeAsStringSync(renderCommandsIndex(discovered));
return discovered;
}