[tools] Add column header for emulators information (#142853)

Add column information as table header for `flutter emulators` command.

**Before:**

```
2 available emulators:

Pixel_3_API_30   • Pixel 3 API 30   • Google • android
Resizable_API_33 • Resizable API 33 • Google • android

To run an emulator, run 'flutter emulators --launch <emulator id>'.
To create a new emulator, run 'flutter emulators --create [--name xyz]'.

You can find more information on managing emulators at the links below:
  https://developer.android.com/studio/run/managing-avds
  https://developer.android.com/studio/command-line/avdmanager
```

**After:**

```
2 available emulators:

Id               • Name             • Manufacturer • Platform

Pixel_3_API_30   • Pixel 3 API 30   • Google       • android
Resizable_API_33 • Resizable API 33 • Google       • android

To run an emulator, run 'flutter emulators --launch <emulator id>'.
To create a new emulator, run 'flutter emulators --create [--name xyz]'.

You can find more information on managing emulators at the links below:
  https://developer.android.com/studio/run/managing-avds
  https://developer.android.com/studio/command-line/avdmanager
```

fixes #140656
This commit is contained in:
Anas 2024-02-14 18:19:24 +05:30 committed by GitHub
parent abadf9ff8c
commit ca03beda4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -291,8 +291,16 @@ abstract class Emulator {
return <String>[];
}
const List<String> tableHeader = <String>[
'Id',
'Name',
'Manufacturer',
'Platform',
];
// Extract emulators information
final List<List<String>> table = <List<String>>[
tableHeader,
for (final Emulator emulator in emulators)
<String>[
emulator.id,
@ -323,7 +331,10 @@ abstract class Emulator {
}
static void printEmulators(List<Emulator> emulators, Logger logger) {
descriptions(emulators).forEach(logger.printStatus);
final List<String> emulatorDescriptions = descriptions(emulators);
// Prints the first description as the table header, followed by a newline.
logger.printStatus('${emulatorDescriptions.first}\n');
emulatorDescriptions.sublist(1).forEach(logger.printStatus);
}
}

View file

@ -87,6 +87,18 @@ void main() {
returnsNormally);
});
testUsingContext('printEmulators prints the the emualtors information with header', () {
Emulator.printEmulators(emulators, testLogger);
expect(testLogger.statusText, '''
Id Name Manufacturer Platform
Nexus_5 Nexus 5 Google android
Nexus_5X_API_27_x86 Nexus 5X Google android
iOS Simulator iOS Simulator Apple android
''');
});
testUsingContext('getEmulators with no Android SDK', () async {
// Test that EmulatorManager.getEmulators() doesn't throw when there's no Android SDK.
final EmulatorManager emulatorManager = EmulatorManager(