Skip to content

Commit b5e159f

Browse files
Suggest the -d flag after interactive device selection (flutter#188941)
When `flutter run` (or any command that resolves a target device) finds multiple devices and no `-d` flag was given, it interactively prompts the user to pick one — but never tells them how to skip that prompt next time. This implements the suggestion from flutter#63541 (and follows the pointer @jmagman gave there): after the user picks a device, print ``` To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d macos". ``` with the id of the device they just chose. The hint is printed in both selection flows: - `TargetDevices._chooseOneOfAvailableDevices` (the standard flow), right after the selection is parsed. - `TargetDevicesWithExtendedWirelessDeviceDiscovery._selectFromDevicesAndCheckForWireless` (the macOS + iOS wireless flow), after the chosen-device future completes rather than inside `TargetDeviceSelection.userSelectDevice` — printing it at selection time would interleave with (and get wiped by) the line-clearing/reprinting that happens when wireless device discovery finishes while the prompt is up. The 17 existing interactive-selection tests that assert the full status text have been updated to include the hint line, and the eleventh-device test now asserts the hint contains the correct id (`-d id-11`) rather than the fake default. Fixes flutter#63541 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Co-authored-by: Ben Konyi <[email protected]>
1 parent 0734985 commit b5e159f

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

‎packages/flutter_tools/lib/src/runner/target_devices.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const _wirelesslyConnectedDevicesMessage = 'Wirelessly connected devices:';
2424

2525
String _chooseDeviceOptionMessage(int option, String name, String deviceId) =>
2626
'[$option]: $name ($deviceId)';
27+
String _skipPromptWithDeviceIdMessage(String deviceId) =>
28+
'To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d $deviceId".';
2729
String _foundMultipleSpecifiedDevicesMessage(String deviceId) =>
2830
'Found multiple devices with name or id matching $deviceId:';
2931
String _foundSpecifiedDevicesMessage(int count, String deviceId) =>
@@ -349,7 +351,9 @@ class TargetDevices {
349351
if (userInput.toLowerCase() == 'q') {
350352
throwToolExit('');
351353
}
352-
return devices[int.parse(userInput) - 1];
354+
final Device chosenDevice = devices[int.parse(userInput) - 1];
355+
_logger.printStatus(_skipPromptWithDeviceIdMessage(chosenDevice.id));
356+
return chosenDevice;
353357
}
354358

355359
void _displayDeviceOptions(List<Device> devices) {
@@ -733,6 +737,11 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
733737
// Wait for user to select a device.
734738
chosenDevice = await futureChosenDevice;
735739

740+
// The hint is printed only after the device is chosen, so that it does
741+
// not interfere with the lines cleared and reprinted once wireless
742+
// devices have loaded.
743+
_logger.printStatus(_skipPromptWithDeviceIdMessage(chosenDevice.id));
744+
736745
// Update the [DeviceManager.specifiedDeviceId] so that the user will not
737746
// be prompted again.
738747
_deviceManager.specifiedDeviceId = chosenDevice.id;

‎packages/flutter_tools/test/general.shard/runner/target_devices_test.dart‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ target-device-5 (wireless) (mobile) • xxx • android • Android 10
666666
667667
[1]: target-device-1 (xxx)
668668
[2]: target-device-5 (wireless) (xxx)
669+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
669670
'''),
670671
);
671672
expect(devices, <Device>[wirelessAndroidDevice1]);
@@ -716,6 +717,7 @@ target-device-1 (mobile) • xxx • android • Android 10
716717
target-device-2 (mobile) • xxx • android • Android 10
717718
[1]: target-device-1 (xxx)
718719
[2]: target-device-2 (xxx)
720+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
719721
'''),
720722
);
721723
expect(devices, <Device>[attachedAndroidDevice1]);
@@ -739,6 +741,13 @@ target-device-2 (mobile) • xxx • android • Android 10
739741
expect(logger.statusText, contains('[11]: target-device-11 (id-11)'));
740742
expect(logger.statusText, contains('Please choose one (or "q" to quit): '));
741743
expect(logger.statusText, isNot(contains('Please choose one (or "q" to quit): 11')));
744+
expect(
745+
logger.statusText,
746+
contains(
747+
'To skip this prompt in the future, pass the device id to the "-d" flag, '
748+
'e.g. "-d id-11".',
749+
),
750+
);
742751
expect(terminal.singleCharMode, isFalse);
743752
expect(deviceManager.androidDiscoverer.devicesCalled, 2);
744753
expect(deviceManager.androidDiscoverer.discoverDevicesCalled, 0);
@@ -765,6 +774,7 @@ target-device-6 (wireless) (mobile) • xxx • android • Android 10
765774
766775
[1]: target-device-5 (wireless) (xxx)
767776
[2]: target-device-6 (wireless) (xxx)
777+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
768778
'''),
769779
);
770780
expect(devices, <Device>[wirelessAndroidDevice1]);
@@ -901,6 +911,7 @@ target-device-8 (wireless) (mobile) • xxx • android • Android 10
901911
[2]: target-device-4 (xxx)
902912
[3]: target-device-5 (wireless) (xxx)
903913
[4]: target-device-8 (wireless) (xxx)
914+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
904915
'''),
905916
);
906917
expect(devices, <Device>[attachedUnsupportedForProjectAndroidDevice]);
@@ -926,6 +937,7 @@ target-device-1 (mobile) • xxx • android • Android 10
926937
target-device-2 (mobile) • xxx • android • Android 10
927938
[1]: target-device-1 (xxx)
928939
[2]: target-device-2 (xxx)
940+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
929941
'''),
930942
);
931943
expect(devices, <Device>[attachedAndroidDevice1]);
@@ -954,6 +966,7 @@ target-device-6 (wireless) (mobile) • xxx • android • Android 10
954966
955967
[1]: target-device-5 (wireless) (xxx)
956968
[2]: target-device-6 (wireless) (xxx)
969+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
957970
'''),
958971
);
959972
expect(devices, <Device>[wirelessAndroidDevice1]);
@@ -1755,7 +1768,8 @@ target-device-9 (mobile) • xxx • ios • iOS 16
17551768
No wireless devices were found.
17561769
17571770
[1]: target-device-9 (xxx)
1758-
Please choose one (or "q" to quit): '''),
1771+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
1772+
'''),
17591773
);
17601774
expect(devices, <Device>[nonEphemeralDevice]);
17611775
expect(deviceManager.iosDiscoverer.devicesCalled, 2);
@@ -1801,7 +1815,8 @@ target-device-9 (mobile) • xxx • ios • iOS 16
18011815
No wireless devices were found.
18021816
18031817
[1]: target-device-9 (xxx)
1804-
Please choose one (or "q" to quit): '''),
1818+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
1819+
'''),
18051820
);
18061821
expect(devices, <Device>[nonEphemeralDevice]);
18071822
}, overrides: <Type, Generator>{AnsiTerminal: () => terminal});
@@ -2147,7 +2162,8 @@ target-device-5 (wireless) (mobile) • xxx • ios • iOS 16
21472162
[1]: target-device-1 (xxx)
21482163
[2]: target-device-2 (xxx)
21492164
[3]: target-device-5 (wireless) (xxx)
2150-
Please choose one (or "q" to quit): '''),
2165+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2166+
'''),
21512167
);
21522168
expect(devices, <Device>[connectedWirelessIOSDevice1]);
21532169
expect(deviceManager.iosDiscoverer.devicesCalled, 2);
@@ -2187,7 +2203,8 @@ No wireless devices were found.
21872203
21882204
[1]: target-device-1 (xxx)
21892205
[2]: target-device-2 (xxx)
2190-
Please choose one (or "q" to quit): '''),
2206+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2207+
'''),
21912208
);
21922209
expect(devices, <Device>[attachedIOSDevice2]);
21932210
expect(deviceManager.iosDiscoverer.devicesCalled, 2);
@@ -2224,6 +2241,7 @@ target-device-6 (wireless) (mobile) • xxx • ios • iOS 16
22242241
22252242
[1]: target-device-5 (wireless) (xxx)
22262243
[2]: target-device-6 (wireless) (xxx)
2244+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
22272245
'''),
22282246
);
22292247
expect(devices, <Device>[connectedWirelessIOSDevice1]);
@@ -2272,6 +2290,7 @@ target-device-5 (wireless) (mobile) • xxx • ios • iOS 16
22722290
[1]: target-device-1 (xxx)
22732291
[2]: target-device-2 (xxx)
22742292
[3]: target-device-5 (wireless) (xxx)
2293+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
22752294
'''),
22762295
);
22772296
expect(devices, <Device>[attachedIOSDevice1]);
@@ -2329,7 +2348,8 @@ target-device-2 (mobile) • xxx • ios • iOS 16
23292348
23302349
[1]: target-device-1 (xxx)
23312350
[2]: target-device-2 (xxx)
2332-
Please choose one (or "q" to quit): '''),
2351+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2352+
'''),
23332353
);
23342354

23352355
expect(devices, <Device>[attachedIOSDevice2]);
@@ -2385,7 +2405,8 @@ target-device-5 (wireless) (mobile) • xxx • ios • iOS 16
23852405
[1]: target-device-1 (xxx)
23862406
[2]: target-device-2 (xxx)
23872407
[3]: target-device-5 (wireless) (xxx)
2388-
Please choose one (or "q" to quit): '''),
2408+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2409+
'''),
23892410
);
23902411

23912412
expect(devices, <Device>[attachedIOSDevice2]);
@@ -2574,7 +2595,8 @@ target-device-8 (wireless) (mobile) • xxx • ios • iOS 16
25742595
[2]: target-device-4 (xxx)
25752596
[3]: target-device-5 (wireless) (xxx)
25762597
[4]: target-device-8 (wireless) (xxx)
2577-
Please choose one (or "q" to quit): '''),
2598+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2599+
'''),
25782600
);
25792601
expect(devices, <Device>[connectedWirelessIOSDevice1]);
25802602
expect(deviceManager.iosDiscoverer.devicesCalled, 3);
@@ -2614,7 +2636,8 @@ No wireless devices were found.
26142636
26152637
[1]: target-device-1 (xxx)
26162638
[2]: target-device-2 (xxx)
2617-
Please choose one (or "q" to quit): '''),
2639+
Please choose one (or "q" to quit): To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
2640+
'''),
26182641
);
26192642
expect(devices, <Device>[attachedIOSDevice2]);
26202643
expect(deviceManager.iosDiscoverer.devicesCalled, 3);
@@ -2649,6 +2672,7 @@ target-device-6 (wireless) (mobile) • xxx • ios • iOS 16
26492672
26502673
[1]: target-device-5 (wireless) (xxx)
26512674
[2]: target-device-6 (wireless) (xxx)
2675+
To skip this prompt in the future, pass the device id to the "-d" flag, e.g. "-d xxx".
26522676
'''),
26532677
);
26542678
expect(devices, <Device>[connectedWirelessIOSDevice1]);

0 commit comments

Comments
 (0)