Skip to content

Commit 37fc9ed

Browse files
authored
[flutter_tools] Clean up boolArgDeprecated and stringArgDeprecated (#122184)
[flutter_tools] Clean up `boolArgDeprecated` and `stringArgDeprecated`
1 parent d8f7c3d commit 37fc9ed

40 files changed

+424
-370
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class AnalyzeCommand extends FlutterCommand {
125125
@override
126126
bool get shouldRunPub {
127127
// If they're not analyzing the current project.
128-
if (!boolArgDeprecated('current-package')) {
128+
if (!boolArg('current-package')) {
129129
return false;
130130
}
131131

@@ -135,7 +135,7 @@ class AnalyzeCommand extends FlutterCommand {
135135
}
136136

137137
// Don't run pub if asking for machine output.
138-
if (boolArg('machine') != null && boolArg('machine')!) {
138+
if (boolArg('machine')) {
139139
return false;
140140
}
141141

@@ -144,12 +144,9 @@ class AnalyzeCommand extends FlutterCommand {
144144

145145
@override
146146
Future<FlutterCommandResult> runCommand() async {
147-
final bool? suggestionFlag = boolArg('suggestions');
148-
final bool machineFlag = boolArg('machine') ?? false;
149-
if (suggestionFlag != null && suggestionFlag == true) {
147+
if (boolArg('suggestions')) {
150148
final String directoryPath;
151-
final bool? watchFlag = boolArg('watch');
152-
if (watchFlag != null && watchFlag) {
149+
if (boolArg('watch')) {
153150
throwToolExit('flag --watch is not compatible with --suggestions');
154151
}
155152
if (workingDirectory == null) {
@@ -171,9 +168,9 @@ class AnalyzeCommand extends FlutterCommand {
171168
allProjectValidators: _allProjectValidators,
172169
userPath: directoryPath,
173170
processManager: _processManager,
174-
machine: machineFlag,
171+
machine: boolArg('machine'),
175172
).run();
176-
} else if (boolArgDeprecated('watch')) {
173+
} else if (boolArg('watch')) {
177174
await AnalyzeContinuously(
178175
argResults!,
179176
runner!.getRepoRoots(),

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class AssembleCommand extends FlutterCommand {
209209
/// The environmental configuration for a build invocation.
210210
Environment createEnvironment() {
211211
final FlutterProject flutterProject = FlutterProject.current();
212-
String? output = stringArgDeprecated('output');
212+
String? output = stringArg('output');
213213
if (output == null) {
214214
throwToolExit('--output directory is required for assemble.');
215215
}
@@ -317,7 +317,7 @@ class AssembleCommand extends FlutterCommand {
317317
environment,
318318
buildSystemConfig: BuildSystemConfig(
319319
resourcePoolSize: argumentResults.wasParsed('resource-pool-size')
320-
? int.tryParse(stringArgDeprecated('resource-pool-size')!)
320+
? int.tryParse(stringArg('resource-pool-size')!)
321321
: null,
322322
),
323323
);
@@ -334,17 +334,17 @@ class AssembleCommand extends FlutterCommand {
334334
globals.printTrace('build succeeded.');
335335

336336
if (argumentResults.wasParsed('build-inputs')) {
337-
writeListIfChanged(result.inputFiles, stringArgDeprecated('build-inputs')!);
337+
writeListIfChanged(result.inputFiles, stringArg('build-inputs')!);
338338
}
339339
if (argumentResults.wasParsed('build-outputs')) {
340-
writeListIfChanged(result.outputFiles, stringArgDeprecated('build-outputs')!);
340+
writeListIfChanged(result.outputFiles, stringArg('build-outputs')!);
341341
}
342342
if (argumentResults.wasParsed('performance-measurement-file')) {
343343
final File outFile = globals.fs.file(argumentResults['performance-measurement-file']);
344344
writePerformanceData(result.performance.values, outFile);
345345
}
346346
if (argumentResults.wasParsed('depfile')) {
347-
final File depfileFile = globals.fs.file(stringArgDeprecated('depfile'));
347+
final File depfileFile = globals.fs.file(stringArg('depfile'));
348348
final Depfile depfile = Depfile(result.inputFiles, result.outputFiles);
349349
final DepfileService depfileService = DepfileService(
350350
fileSystem: globals.fs,

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,33 +181,34 @@ known, it can be explicitly provided to attach via the command-line, e.g.
181181
return null;
182182
}
183183
try {
184-
return int.parse(stringArgDeprecated('debug-port')!);
184+
return int.parse(stringArg('debug-port')!);
185185
} on Exception catch (error) {
186186
throwToolExit('Invalid port for `--debug-port`: $error');
187187
}
188188
}
189189

190190
Uri? get debugUri {
191-
if (argResults!['debug-url'] == null) {
191+
final String? debugUrl = stringArg('debug-url');
192+
if (debugUrl == null) {
192193
return null;
193194
}
194-
final Uri? uri = Uri.tryParse(stringArgDeprecated('debug-url')!);
195+
final Uri? uri = Uri.tryParse(debugUrl);
195196
if (uri == null) {
196-
throwToolExit('Invalid `--debug-url`: ${stringArgDeprecated('debug-url')}');
197+
throwToolExit('Invalid `--debug-url`: $debugUrl');
197198
}
198199
if (!uri.hasPort) {
199200
throwToolExit('Port not specified for `--debug-url`: $uri');
200201
}
201202
return uri;
202203
}
203204

204-
bool get serveObservatory => boolArg('serve-observatory') ?? false;
205+
bool get serveObservatory => boolArg('serve-observatory');
205206

206207
String? get appId {
207-
return stringArgDeprecated('app-id');
208+
return stringArg('app-id');
208209
}
209210

210-
String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser);
211+
String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
211212

212213
@override
213214
Future<void> validateCommand() async {
@@ -268,7 +269,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
268269
Future<void> _attachToDevice(Device device) async {
269270
final FlutterProject flutterProject = FlutterProject.current();
270271

271-
final Daemon? daemon = boolArgDeprecated('machine')
272+
final Daemon? daemon = boolArg('machine')
272273
? Daemon(
273274
DaemonConnection(
274275
daemonStreams: DaemonStreams.fromStdio(_stdio, logger: _logger),
@@ -290,7 +291,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
290291

291292
if ((debugPort == null && debugUri == null) || isNetworkDevice) {
292293
if (device is FuchsiaDevice) {
293-
final String? module = stringArgDeprecated('module');
294+
final String? module = stringArg('module');
294295
if (module == null) {
295296
throwToolExit("'--module' is required for attaching to a Fuchsia device");
296297
}
@@ -428,7 +429,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
428429
connectionInfoCompleter: connectionInfoCompleter,
429430
appStartedCompleter: appStartedCompleter,
430431
allowExistingDdsInstance: true,
431-
enableDevTools: boolArgDeprecated(FlutterCommand.kEnableDevTools),
432+
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
432433
);
433434
},
434435
device,
@@ -460,16 +461,16 @@ known, it can be explicitly provided to attach via the command-line, e.g.
460461
terminal: _terminal,
461462
signals: _signals,
462463
processInfo: _processInfo,
463-
reportReady: boolArgDeprecated('report-ready'),
464-
pidFile: stringArgDeprecated('pid-file'),
464+
reportReady: boolArg('report-ready'),
465+
pidFile: stringArg('pid-file'),
465466
)
466467
..registerSignalHandlers()
467468
..setupTerminal();
468469
}));
469470
result = await runner.attach(
470471
appStartedCompleter: onAppStart,
471472
allowExistingDdsInstance: true,
472-
enableDevTools: boolArgDeprecated(FlutterCommand.kEnableDevTools),
473+
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
473474
);
474475
if (result != 0) {
475476
throwToolExit(null, exitCode: result);
@@ -505,7 +506,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
505506
final FlutterDevice flutterDevice = await FlutterDevice.create(
506507
device,
507508
target: targetFile,
508-
targetModel: TargetModel(stringArgDeprecated('target-model')!),
509+
targetModel: TargetModel(stringArg('target-model')!),
509510
buildInfo: buildInfo,
510511
userIdentifier: userIdentifier,
511512
platform: _platform,
@@ -526,8 +527,8 @@ known, it can be explicitly provided to attach via the command-line, e.g.
526527
target: targetFile,
527528
debuggingOptions: debuggingOptions,
528529
packagesFilePath: globalResults!['packages'] as String?,
529-
projectRootPath: stringArgDeprecated('project-root'),
530-
dillOutputPath: stringArgDeprecated('output-dill'),
530+
projectRootPath: stringArg('project-root'),
531+
dillOutputPath: stringArg('output-dill'),
531532
ipv6: usesIpv6,
532533
flutterProject: flutterProject,
533534
)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import '../android/android_builder.dart';
66
import '../android/android_sdk.dart';
77
import '../android/gradle_utils.dart';
88
import '../base/common.dart';
9-
109
import '../base/file_system.dart';
1110
import '../base/os.dart';
1211
import '../build_info.dart';
@@ -113,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand {
113112
final Iterable<AndroidArch> targetArchitectures =
114113
stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName);
115114

116-
final String? buildNumberArg = stringArgDeprecated('build-number');
115+
final String? buildNumberArg = stringArg('build-number');
117116
final String buildNumber = argParser.options.containsKey('build-number')
118117
&& buildNumberArg != null
119118
&& buildNumberArg.isNotEmpty
@@ -122,7 +121,7 @@ class BuildAarCommand extends BuildSubCommand {
122121

123122
final File targetFile = _fileSystem.file(_fileSystem.path.join('lib', 'main.dart'));
124123
for (final String buildMode in const <String>['debug', 'profile', 'release']) {
125-
if (boolArgDeprecated(buildMode)) {
124+
if (boolArg(buildMode)) {
126125
androidBuildInfo.add(
127126
AndroidBuildInfo(
128127
await getBuildInfo(

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class BuildApkCommand extends BuildSubCommand {
5858
final String name = 'apk';
5959

6060
@override
61-
DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
61+
DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
6262

63-
bool get configOnly => boolArg('config-only') ?? false;
63+
bool get configOnly => boolArg('config-only');
6464

6565
@override
6666
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
@@ -80,11 +80,11 @@ class BuildApkCommand extends BuildSubCommand {
8080
Future<CustomDimensions> get usageValues async {
8181
String buildMode;
8282

83-
if (boolArgDeprecated('release')) {
83+
if (boolArg('release')) {
8484
buildMode = 'release';
85-
} else if (boolArgDeprecated('debug')) {
85+
} else if (boolArg('debug')) {
8686
buildMode = 'debug';
87-
} else if (boolArgDeprecated('profile')) {
87+
} else if (boolArg('profile')) {
8888
buildMode = 'profile';
8989
} else {
9090
// The build defaults to release.
@@ -94,7 +94,7 @@ class BuildApkCommand extends BuildSubCommand {
9494
return CustomDimensions(
9595
commandBuildApkTargetPlatform: stringsArg('target-platform').join(','),
9696
commandBuildApkBuildMode: buildMode,
97-
commandBuildApkSplitPerAbi: boolArgDeprecated('split-per-abi'),
97+
commandBuildApkSplitPerAbi: boolArg('split-per-abi'),
9898
);
9999
}
100100

@@ -106,9 +106,9 @@ class BuildApkCommand extends BuildSubCommand {
106106
final BuildInfo buildInfo = await getBuildInfo();
107107
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(
108108
buildInfo,
109-
splitPerAbi: boolArgDeprecated('split-per-abi'),
109+
splitPerAbi: boolArg('split-per-abi'),
110110
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
111-
multidexEnabled: boolArgDeprecated('multidex'),
111+
multidexEnabled: boolArg('multidex'),
112112
);
113113
validateBuild(androidBuildInfo);
114114
displayNullSafetyMode(androidBuildInfo.buildInfo);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
7070
final String name = 'appbundle';
7171

7272
@override
73-
DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
73+
DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
7474

7575
@override
7676
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
@@ -88,11 +88,11 @@ class BuildAppBundleCommand extends BuildSubCommand {
8888
Future<CustomDimensions> get usageValues async {
8989
String buildMode;
9090

91-
if (boolArgDeprecated('release')) {
91+
if (boolArg('release')) {
9292
buildMode = 'release';
93-
} else if (boolArgDeprecated('debug')) {
93+
} else if (boolArg('debug')) {
9494
buildMode = 'debug';
95-
} else if (boolArgDeprecated('profile')) {
95+
} else if (boolArg('profile')) {
9696
buildMode = 'profile';
9797
} else {
9898
// The build defaults to release.
@@ -113,12 +113,12 @@ class BuildAppBundleCommand extends BuildSubCommand {
113113

114114
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(await getBuildInfo(),
115115
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
116-
multidexEnabled: boolArgDeprecated('multidex'),
116+
multidexEnabled: boolArg('multidex'),
117117
);
118118
// Do all setup verification that doesn't involve loading units. Checks that
119119
// require generated loading units are done after gen_snapshot in assemble.
120120
final List<DeferredComponent>? deferredComponents = FlutterProject.current().manifest.deferredComponents;
121-
if (deferredComponents != null && boolArgDeprecated('deferred-components') && boolArgDeprecated('validate-deferred-components') && !boolArgDeprecated('debug')) {
121+
if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) {
122122
final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator(
123123
FlutterProject.current().directory,
124124
globals.logger,
@@ -154,8 +154,8 @@ class BuildAppBundleCommand extends BuildSubCommand {
154154
project: FlutterProject.current(),
155155
target: targetFile,
156156
androidBuildInfo: androidBuildInfo,
157-
validateDeferredComponents: boolArgDeprecated('validate-deferred-components'),
158-
deferredComponentsEnabled: boolArgDeprecated('deferred-components') && !boolArgDeprecated('debug'),
157+
validateDeferredComponents: boolArg('validate-deferred-components'),
158+
deferredComponentsEnabled: boolArg('deferred-components') && !boolArg('debug'),
159159
);
160160
return FlutterCommandResult.success();
161161
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ class BuildBundleCommand extends BuildSubCommand {
7878
final String projectDir = globals.fs.file(targetFile).parent.parent.path;
7979
final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectDir));
8080
return CustomDimensions(
81-
commandBuildBundleTargetPlatform: stringArgDeprecated('target-platform'),
81+
commandBuildBundleTargetPlatform: stringArg('target-platform'),
8282
commandBuildBundleIsModule: flutterProject.isModule,
8383
);
8484
}
8585

8686
@override
8787
Future<void> validateCommand() async {
88-
if (boolArgDeprecated('tree-shake-icons')) {
88+
if (boolArg('tree-shake-icons')) {
8989
throwToolExit('The "--tree-shake-icons" flag is deprecated for "build bundle" and will be removed in a future version of Flutter.');
9090
}
9191
return super.validateCommand();
9292
}
9393

9494
@override
9595
Future<FlutterCommandResult> runCommand() async {
96-
final String targetPlatform = stringArgDeprecated('target-platform')!;
96+
final String targetPlatform = stringArg('target-platform')!;
9797
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
9898
// Check for target platforms that are only allowed via feature flags.
9999
switch (platform) {
@@ -133,8 +133,8 @@ class BuildBundleCommand extends BuildSubCommand {
133133
platform: platform,
134134
buildInfo: buildInfo,
135135
mainPath: targetFile,
136-
depfilePath: stringArgDeprecated('depfile'),
137-
assetDirPath: stringArgDeprecated('asset-dir'),
136+
depfilePath: stringArg('depfile'),
137+
assetDirPath: stringArg('asset-dir'),
138138
);
139139
return FlutterCommandResult.success();
140140
}

0 commit comments

Comments
 (0)