Skip to content

Commit 3396ec7

Browse files
authored
Device discovery output cleanup (#131223)
Fixes flutter/flutter#6538
1 parent 096b7c3 commit 3396ec7

File tree

3 files changed

+163
-129
lines changed

3 files changed

+163
-129
lines changed

packages/flutter_tools/lib/src/commands/devices.dart

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,48 +168,43 @@ class DevicesCommandOutput {
168168
}
169169

170170
if (allDevices.isEmpty) {
171-
_printNoDevicesDetected();
171+
_logger.printStatus('No authorized devices detected.');
172172
} else {
173173
if (attachedDevices.isNotEmpty) {
174-
_logger.printStatus('${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:\n');
175-
await Device.printDevices(attachedDevices, _logger);
174+
_logger.printStatus('Found ${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:');
175+
await Device.printDevices(attachedDevices, _logger, prefix: ' ');
176176
}
177177
if (wirelessDevices.isNotEmpty) {
178178
if (attachedDevices.isNotEmpty) {
179179
_logger.printStatus('');
180180
}
181-
_logger.printStatus('${wirelessDevices.length} wirelessly connected ${pluralize('device', wirelessDevices.length)}:\n');
182-
await Device.printDevices(wirelessDevices, _logger);
181+
_logger.printStatus('Found ${wirelessDevices.length} wirelessly connected ${pluralize('device', wirelessDevices.length)}:');
182+
await Device.printDevices(wirelessDevices, _logger, prefix: ' ');
183183
}
184184
}
185-
await _printDiagnostics();
185+
await _printDiagnostics(foundAny: allDevices.isNotEmpty);
186186
}
187187

188-
void _printNoDevicesDetected() {
189-
final StringBuffer status = StringBuffer('No devices detected.');
190-
status.writeln();
188+
Future<void> _printDiagnostics({ required bool foundAny }) async {
189+
final StringBuffer status = StringBuffer();
191190
status.writeln();
191+
final List<String> diagnostics = await _deviceManager?.getDeviceDiagnostics() ?? <String>[];
192+
if (diagnostics.isNotEmpty) {
193+
for (final String diagnostic in diagnostics) {
194+
status.writeln(diagnostic);
195+
status.writeln();
196+
}
197+
}
192198
status.writeln('Run "flutter emulators" to list and start any available device emulators.');
193199
status.writeln();
194-
status.write('If you expected your device to be detected, please run "flutter doctor" to diagnose potential issues. ');
200+
status.write('If you expected ${ foundAny ? 'another' : 'a' } device to be detected, please run "flutter doctor" to diagnose potential issues. ');
195201
if (deviceDiscoveryTimeout == null) {
196-
status.write('You may also try increasing the time to wait for connected devices with the --${FlutterOptions.kDeviceTimeout} flag. ');
202+
status.write('You may also try increasing the time to wait for connected devices with the "--${FlutterOptions.kDeviceTimeout}" flag. ');
197203
}
198204
status.write('Visit https://flutter.dev/setup/ for troubleshooting tips.');
199-
200205
_logger.printStatus(status.toString());
201206
}
202207

203-
Future<void> _printDiagnostics() async {
204-
final List<String> diagnostics = await _deviceManager?.getDeviceDiagnostics() ?? <String>[];
205-
if (diagnostics.isNotEmpty) {
206-
_logger.printStatus('');
207-
for (final String diagnostic in diagnostics) {
208-
_logger.printStatus('• $diagnostic', hangingIndent: 2);
209-
}
210-
}
211-
}
212-
213208
Future<void> printDevicesAsJson(List<Device> devices) async {
214209
_logger.printStatus(
215210
const JsonEncoder.withIndent(' ').convert(
@@ -266,8 +261,8 @@ class DevicesCommandOutputWithExtendedWirelessDeviceDiscovery extends DevicesCom
266261

267262
// Display list of attached devices.
268263
if (attachedDevices.isNotEmpty) {
269-
_logger.printStatus('${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:\n');
270-
await Device.printDevices(attachedDevices, _logger);
264+
_logger.printStatus('Found ${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:');
265+
await Device.printDevices(attachedDevices, _logger, prefix: ' ');
271266
_logger.printStatus('');
272267
numLinesToClear += 1;
273268
}
@@ -292,8 +287,8 @@ class DevicesCommandOutputWithExtendedWirelessDeviceDiscovery extends DevicesCom
292287
if (_logger.isVerbose && _includeAttachedDevices) {
293288
// Reprint the attach devices.
294289
if (attachedDevices.isNotEmpty) {
295-
_logger.printStatus('\n${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:\n');
296-
await Device.printDevices(attachedDevices, _logger);
290+
_logger.printStatus('\nFound ${attachedDevices.length} connected ${pluralize('device', attachedDevices.length)}:');
291+
await Device.printDevices(attachedDevices, _logger, prefix: ' ');
297292
}
298293
} else if (terminal.supportsColor && terminal is AnsiTerminal) {
299294
_logger.printStatus(
@@ -309,16 +304,16 @@ class DevicesCommandOutputWithExtendedWirelessDeviceDiscovery extends DevicesCom
309304
if (wirelessDevices.isEmpty) {
310305
if (attachedDevices.isEmpty) {
311306
// No wireless or attached devices were found.
312-
_printNoDevicesDetected();
307+
_logger.printStatus('No authorized devices detected.');
313308
} else {
314309
// Attached devices found, wireless devices not found.
315310
_logger.printStatus(_noWirelessDevicesFoundMessage);
316311
}
317312
} else {
318313
// Display list of wireless devices.
319-
_logger.printStatus('${wirelessDevices.length} wirelessly connected ${pluralize('device', wirelessDevices.length)}:\n');
320-
await Device.printDevices(wirelessDevices, _logger);
314+
_logger.printStatus('Found ${wirelessDevices.length} wirelessly connected ${pluralize('device', wirelessDevices.length)}:');
315+
await Device.printDevices(wirelessDevices, _logger, prefix: ' ');
321316
}
322-
await _printDiagnostics();
317+
await _printDiagnostics(foundAny: wirelessDevices.isNotEmpty || attachedDevices.isNotEmpty);
323318
}
324319
}

packages/flutter_tools/lib/src/device.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,10 @@ abstract class Device {
849849
];
850850
}
851851

852-
static Future<void> printDevices(List<Device> devices, Logger logger) async {
853-
(await descriptions(devices)).forEach(logger.printStatus);
852+
static Future<void> printDevices(List<Device> devices, Logger logger, { String prefix = '' }) async {
853+
for (final String line in await descriptions(devices)) {
854+
logger.printStatus('$prefix$line');
855+
}
854856
}
855857

856858
static List<String> devicesPlatformTypes(List<Device> devices) {

0 commit comments

Comments
 (0)