Skip to content

Commit 33cc994

Browse files
kevmoosuryaKommana2662
authored andcommitted
refactor(flutter_tools): remove legacy uses*/add* option registration helpers from FlutterCommand (flutter#194521)
Part of flutter#194338 Completes the migration of `flutter_tools` commands to declarative `OptionDescriptor` and `OptionBundle` registrations and removes the 47 legacy `uses*` and `add*` option-registration helper methods and 5 `enableUses*()` boolean setters from `FlutterCommand` (`+211 / -428` lines): - Adds `WebServerOptionsBundle` in `lib/src/web/web_options.dart` and registers it in `RunCommandBase`. - Migrates the remaining leaf commands (`analyze`, `build`, `build_bundle`, `debug_adapter`, `devices`, `generate`, `install`, `logs`, `screenshot`, and `widget_preview`) and test fixtures (`build_test.dart`, `flutter_command_runner_test.dart`, `flutter_command_test.dart`, `option_descriptor_test.dart`) off the imperative `uses*` / `add*` methods. - Deletes all 47 legacy `uses*` and `add*` option-registration helper methods (and `_usesDartDefineFromFileOption`) from `FlutterCommand` in `lib/src/runner/flutter_command.dart`. - Replaces all 5 `enableUses*()` methods and `_uses*` fields on `FlutterCommand` with `hasOption(...)` checks (verifying descriptor identity on `argParser` via `OptionDescriptor.isRegisteredOnParser`). ## 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. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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
1 parent 94bf3fa commit 33cc994

24 files changed

Lines changed: 322 additions & 416 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class AnalyzeCommand extends FlutterCommand {
7676
hide: !verboseHelp,
7777
);
7878
argParser.addFlag('suggestions', help: 'Show suggestions about the current flutter project.');
79-
addMachineOutputFlag(verboseHelp: verboseHelp);
79+
CommonOptions.machine.addTo(argParser, verboseHelp: verboseHelp);
8080

8181
// Hidden option to enable a benchmarking mode.
8282
argParser.addFlag(
@@ -87,7 +87,7 @@ class AnalyzeCommand extends FlutterCommand {
8787
);
8888
argParser.addFlag('plugins', defaultsTo: true, help: 'Whether to enable analyzer plugins.');
8989

90-
usesPubOption();
90+
CommonOptions.pub.addTo(argParser);
9191

9292
// Not used by analyze --watch
9393
argParser.addFlag(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class AttachCommand extends FlutterCommand {
7272
super.verboseHelp = false,
7373
}) : _hotRunnerFactory = hotRunnerFactory ?? HotRunnerFactory(),
7474
_toolContext = toolContext {
75-
enableUsesTargetOption();
7675
registerOptionBundles(const <OptionBundle>[
7776
BuildModeOptionsBundle(defaultToRelease: false, excludeRelease: true),
7877
VmServicePortOptionsBundle(),

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ abstract class BuildSubCommand extends FlutterCommand {
260260
super.toolContext,
261261
}) {
262262
requiresPubspecYaml();
263-
usesFatalWarningsOption(verboseHelp: verboseHelp);
263+
CommonOptions.fatalWarnings.addTo(argParser, verboseHelp: verboseHelp);
264264
}
265265

266266
@protected
@@ -282,9 +282,11 @@ class ExtensionBuildSubCommand extends BuildSubCommand {
282282
outputPreferences: toolContext.outputPreferences,
283283
toolContext: toolContext,
284284
) {
285-
usesTargetOption();
286-
usesPubOption();
287-
addBuildModeFlags(verboseHelp: verboseHelp);
285+
registerOptionBundle(const BuildModeOptionsBundle());
286+
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
287+
CommonOptions.target,
288+
CommonOptions.pub,
289+
], verboseHelp: verboseHelp);
288290
}
289291

290292
final ExtensionBuildManager _buildManager;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class BuildAarCommand extends BuildSubCommand {
2727
required ToolContext toolContext,
2828
super.verboseHelp = false,
2929
}) : super(logger: toolContext.logger, toolContext: toolContext) {
30-
enableUsesPubOption();
3130
registerOptionBundles(const <OptionBundle>[
3231
DartCompileOptionsBundle(),
3332
AndroidGradleOptionsBundle(),

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ class BuildBundleCommand extends BuildSubCommand {
2929
outputPreferences: toolContext.outputPreferences,
3030
toolContext: toolContext,
3131
) {
32-
usesTargetOption();
33-
usesFilesystemOptions(hide: !verboseHelp);
34-
usesBuildNumberOption();
35-
addBuildModeFlags(verboseHelp: verboseHelp, defaultToRelease: false);
36-
usesDartDefineOption();
37-
usesExtraDartFlagOptions(verboseHelp: verboseHelp);
32+
registerOptionBundles(const <OptionBundle>[
33+
FilesystemOptionsBundle(),
34+
BuildModeOptionsBundle(defaultToRelease: false),
35+
]);
36+
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
37+
CommonOptions.target,
38+
CommonOptions.buildNumber,
39+
CommonOptions.dartDefines,
40+
CommonOptions.dartDefineFromFile,
41+
BuildInfoOptions.extraFrontEndOptions,
42+
BuildInfoOptions.extraGenSnapshotOptions,
43+
CommonOptions.pub,
44+
BuildInfoOptions.trackWidgetCreation,
45+
], verboseHelp: verboseHelp);
3846
argParser
3947
..addOption(
4048
'depfile',
@@ -75,8 +83,6 @@ class BuildBundleCommand extends BuildSubCommand {
7583
hide: !verboseHelp,
7684
help: '(deprecated) Icon font tree shaking is not supported by this command.',
7785
);
78-
usesPubOption();
79-
usesTrackWidgetCreation(verboseHelp: verboseHelp);
8086
}
8187

8288
final BuildSystem buildSystem;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import '../runner/flutter_command.dart';
2525
/// The DAP specification can be found at
2626
/// https://microsoft.github.io/debug-adapter-protocol/.
2727
class DebugAdapterCommand extends FlutterCommand {
28-
DebugAdapterCommand({required super.toolContext, bool verboseHelp = false})
29-
: hidden = !verboseHelp {
30-
usesIpv6Flag(verboseHelp: verboseHelp);
31-
addDdsOptions(verboseHelp: verboseHelp);
28+
DebugAdapterCommand({required super.toolContext, super.verboseHelp}) : hidden = !verboseHelp {
29+
DebuggingOptionDescriptors.ipv6.addTo(argParser, verboseHelp: verboseHelp);
30+
registerOptionBundle(const DdsAndDevToolsOptionsBundle(includeDevTools: false));
3231
argParser.addFlag(
3332
'test',
3433
help:

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ class DevicesCommand extends FlutterCommand {
2121
required super.toolContext,
2222
super.verboseHelp,
2323
}) {
24-
addMachineOutputFlag(verboseHelp: verboseHelp);
24+
CommonOptions.machine.addTo(argParser, verboseHelp: verboseHelp);
2525
argParser.addOption(
2626
'timeout',
2727
abbr: 't',
2828
help: '(deprecated) This option has been replaced by "--${FlutterOptions.kDeviceTimeout}".',
2929
hide: !verboseHelp,
3030
);
31-
usesDeviceTimeoutOption();
32-
usesDeviceConnectionOption();
31+
registerOptionBundle(const DeviceDiscoveryOptionsBundle());
3332
}
3433

3534
final DeviceManager _deviceManager;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '../runner/flutter_command.dart';
77

88
class GenerateCommand extends FlutterCommand {
99
GenerateCommand({required ToolContext super.toolContext}) : _toolContext = toolContext {
10-
usesTargetOption();
10+
CommonOptions.target.addTo(argParser);
1111
}
1212

1313
final ToolContext _toolContext;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import '../runner/flutter_command.dart';
1414

1515
class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
1616
InstallCommand({required ToolContext super.toolContext, required super.verboseHelp}) {
17-
addBuildModeFlags(verboseHelp: verboseHelp);
1817
requiresPubspecYaml();
19-
usesApplicationBinaryOption();
20-
usesDeviceTimeoutOption();
21-
usesDeviceConnectionOption();
22-
usesDeviceUserOption();
23-
usesFlavorOption();
18+
registerOptionBundles(const <OptionBundle>[
19+
BuildModeOptionsBundle(),
20+
DeviceDiscoveryOptionsBundle(includeDeviceUser: true),
21+
]);
22+
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
23+
CommonOptions.useApplicationBinary,
24+
BuildInfoOptions.flavor,
25+
], verboseHelp: verboseHelp);
2426
argParser.addFlag(
2527
'uninstall-only',
2628
help: 'Uninstall the app if already on the device. Skip install.',

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class LogsCommand extends FlutterCommand {
2929
abbr: 'c',
3030
help: 'Clear log history before reading from logs.',
3131
);
32-
usesDeviceTimeoutOption();
33-
usesDeviceConnectionOption();
34-
usesAdbLogFilteringOption(hide: false);
32+
registerOptionBundle(const DeviceDiscoveryOptionsBundle());
33+
DebuggingOptionDescriptors.adbLogFiltering.addTo(argParser, hideOverride: false);
3534
}
3635

3736
final ProcessSignal _sigint;

0 commit comments

Comments
 (0)