Skip to content

Commit 669265b

Browse files
authored
refactor(flutter_tools): finish DriveCommand OptionDescriptor migration (flutter#194360)
Completes the `flutter drive` migration to typed option descriptors and shared option definitions from flutter#194356, removing the last untyped argument lookups in `drive.dart`. Part of flutter#194338 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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.
1 parent 061eaac commit 669265b

3 files changed

Lines changed: 36 additions & 36 deletions

File tree

‎packages/flutter_tools/lib/src/commands/drive.dart‎

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66

7-
import 'package:args/args.dart';
87
import 'package:meta/meta.dart';
98
import 'package:package_config/package_config_types.dart';
109

@@ -61,17 +60,17 @@ class DriveCommand extends RunCommandBase {
6160
super.verboseHelp = false,
6261
}) {
6362
requiresPubspecYaml();
64-
addEnableExperimentation(hide: !verboseHelp);
6563

66-
// By default, the drive app should not publish the VM service port over mDNS
67-
// to prevent a local network permission dialog on iOS 14+,
68-
// which cannot be accepted or dismissed in a CI environment.
69-
addPublishPort(enabledByDefault: false, verboseHelp: verboseHelp);
70-
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
64+
argParser.addDescriptors(<OptionDescriptor<Object?>>[
65+
CommonOptions.enableExperiment,
66+
// By default, the drive app should not publish the VM service port over mDNS
67+
// to prevent a local network permission dialog on iOS 14+,
68+
// which cannot be accepted or dismissed in a CI environment.
69+
_publishPort,
7170
_keepAppRunning,
7271
_useExistingApp,
7372
_driver,
74-
_build,
73+
DebuggingOptionDescriptors.build,
7574
_screenshot,
7675
_driverPort,
7776
_headless,
@@ -85,6 +84,10 @@ class DriveCommand extends RunCommandBase {
8584
], verboseHelp: verboseHelp);
8685
}
8786

87+
static final FlagOptionDescriptor _publishPort = DebuggingOptionDescriptors.publishPortOption(
88+
enabledByDefault: false,
89+
);
90+
8891
static const _kKeepAppRunning = 'keep-app-running';
8992
static const _kUseExistingApp = 'use-existing-app';
9093

@@ -119,14 +122,6 @@ class DriveCommand extends RunCommandBase {
119122
valueHelp: 'path',
120123
);
121124

122-
static const _build = FlagOptionDescriptor(
123-
name: 'build',
124-
defaultsTo: true,
125-
help:
126-
'(deprecated) Build the app before running. To use an existing app, pass the "--${FlutterOptions.kUseApplicationBinary}" '
127-
'flag with an existing APK.',
128-
);
129-
130125
static const _screenshot = StringOptionDescriptor(
131126
name: 'screenshot',
132127
valueHelp: 'path/to/directory',
@@ -241,7 +236,7 @@ class DriveCommand extends RunCommandBase {
241236
@override
242237
final aliases = <String>['driver'];
243238

244-
String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
239+
String? get userIdentifier => getValue(CommonOptions.deviceUser);
245240

246241
String? get screenshot => getValue(_screenshot);
247242

@@ -251,7 +246,7 @@ class DriveCommand extends RunCommandBase {
251246
@override
252247
bool get cachePubGet => false;
253248

254-
String? get applicationBinaryPath => stringArg(FlutterOptions.kUseApplicationBinary);
249+
String? get applicationBinaryPath => getValue(CommonOptions.useApplicationBinary);
255250

256251
Future<Device?> get targetedDevice async {
257252
return findTargetDevice(includeDevicesUnsupportedByProject: applicationBinaryPath == null);
@@ -262,18 +257,15 @@ class DriveCommand extends RunCommandBase {
262257
// change it to be enabled.
263258
@override
264259
Future<bool> get disablePortPublication async {
265-
final ArgResults? localArgResults = argResults;
266260
final Device? device = await targetedDevice;
267261
final bool isWirelessIOSDevice = device is IOSDevice && device.isWirelesslyConnected;
268-
if (isWirelessIOSDevice &&
269-
localArgResults != null &&
270-
!localArgResults.wasParsed('publish-port')) {
262+
if (isWirelessIOSDevice && argResults != null && !wasParsed(_publishPort)) {
271263
toolContext.logger.printTrace(
272264
'A wireless iOS device is being used. Changing `publish-port` to be enabled.',
273265
);
274266
return false;
275267
}
276-
return !boolArg('publish-port');
268+
return !getValue(_publishPort);
277269
}
278270

279271
@override

‎packages/flutter_tools/lib/src/runner/options/common_options.dart‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,17 +1282,4 @@ abstract final class DebuggingOptionDescriptors {
12821282
'(deprecated) If necessary, build the app before running. To use an existing app, '
12831283
'pass the "--${FlutterOptions.kUseApplicationBinary}" flag with an existing application artifact.',
12841284
);
1285-
1286-
static FlagOptionDescriptor buildOption({bool verboseOnly = true}) {
1287-
if (verboseOnly) {
1288-
return build;
1289-
}
1290-
return const FlagOptionDescriptor(
1291-
name: 'build',
1292-
defaultsTo: true,
1293-
help:
1294-
'(deprecated) If necessary, build the app before running. To use an existing app, '
1295-
'pass the "--${FlutterOptions.kUseApplicationBinary}" flag with an existing application artifact.',
1296-
);
1297-
}
12981285
}

‎packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,27 @@ void main() {}
10041004
);
10051005
});
10061006

1007+
testUsingContext(
1008+
'disablePortPublication defaults to true when argResults is null',
1009+
() async {
1010+
final Device wirelessDevice = FakeIosDevice()
1011+
..connectionInterface = DeviceConnectionInterface.wireless;
1012+
fakeDeviceManager.wirelessDevices = <Device>[wirelessDevice];
1013+
final command = DriveCommand(
1014+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1015+
buildTargets: const BuildTargetsImpl(),
1016+
toolContext: createToolContext(),
1017+
);
1018+
1019+
expect(await command.disablePortPublication, isTrue);
1020+
},
1021+
overrides: <Type, Generator>{
1022+
FileSystem: () => fileSystem,
1023+
ProcessManager: () => FakeProcessManager.any(),
1024+
DeviceManager: () => fakeDeviceManager,
1025+
},
1026+
);
1027+
10071028
for (final String flag in AndroidEngineCliFlags.allFlags) {
10081029
testUsingContext(
10091030
'fails when --use-application-binary is provided with --release and --$flag for Android',

0 commit comments

Comments
 (0)