Skip to content

Commit 596e9d1

Browse files
authored
[flutter_tools] stringArg refactor (#103231)
1 parent 9511638 commit 596e9d1

29 files changed

+195
-160
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class AssembleCommand extends FlutterCommand {
215215
/// The environmental configuration for a build invocation.
216216
Environment createEnvironment() {
217217
final FlutterProject flutterProject = FlutterProject.current();
218-
String? output = stringArg('output');
218+
String? output = stringArgDeprecated('output');
219219
if (output == null) {
220220
throwToolExit('--output directory is required for assemble.');
221221
}
@@ -318,7 +318,7 @@ class AssembleCommand extends FlutterCommand {
318318
environment,
319319
buildSystemConfig: BuildSystemConfig(
320320
resourcePoolSize: argumentResults.wasParsed('resource-pool-size')
321-
? int.tryParse(stringArg('resource-pool-size')!)
321+
? int.tryParse(stringArgDeprecated('resource-pool-size')!)
322322
: null,
323323
),
324324
);
@@ -335,17 +335,17 @@ class AssembleCommand extends FlutterCommand {
335335
globals.printTrace('build succeeded.');
336336

337337
if (argumentResults.wasParsed('build-inputs')) {
338-
writeListIfChanged(result.inputFiles, stringArg('build-inputs')!);
338+
writeListIfChanged(result.inputFiles, stringArgDeprecated('build-inputs')!);
339339
}
340340
if (argumentResults.wasParsed('build-outputs')) {
341-
writeListIfChanged(result.outputFiles, stringArg('build-outputs')!);
341+
writeListIfChanged(result.outputFiles, stringArgDeprecated('build-outputs')!);
342342
}
343343
if (argumentResults.wasParsed('performance-measurement-file')) {
344344
final File outFile = globals.fs.file(argumentResults['performance-measurement-file']);
345345
writePerformanceData(result.performance.values, outFile);
346346
}
347347
if (argumentResults.wasParsed('depfile')) {
348-
final File depfileFile = globals.fs.file(stringArg('depfile'));
348+
final File depfileFile = globals.fs.file(stringArgDeprecated('depfile'));
349349
final Depfile depfile = Depfile(result.inputFiles, result.outputFiles);
350350
final DepfileService depfileService = DepfileService(
351351
fileSystem: globals.fs,

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
153153
return null;
154154
}
155155
try {
156-
return int.parse(stringArg('debug-port'));
156+
return int.parse(stringArgDeprecated('debug-port'));
157157
} on Exception catch (error) {
158158
throwToolExit('Invalid port for `--debug-port`: $error');
159159
}
@@ -163,9 +163,9 @@ known, it can be explicitly provided to attach via the command-line, e.g.
163163
if (argResults['debug-url'] == null) {
164164
return null;
165165
}
166-
final Uri uri = Uri.tryParse(stringArg('debug-url'));
166+
final Uri uri = Uri.tryParse(stringArgDeprecated('debug-url'));
167167
if (uri == null) {
168-
throwToolExit('Invalid `--debug-url`: ${stringArg('debug-url')}');
168+
throwToolExit('Invalid `--debug-url`: ${stringArgDeprecated('debug-url')}');
169169
}
170170
if (!uri.hasPort) {
171171
throwToolExit('Port not specified for `--debug-url`: $uri');
@@ -174,10 +174,10 @@ known, it can be explicitly provided to attach via the command-line, e.g.
174174
}
175175

176176
String get appId {
177-
return stringArg('app-id');
177+
return stringArgDeprecated('app-id');
178178
}
179179

180-
String get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
180+
String get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser);
181181

182182
@override
183183
Future<void> validateCommand() async {
@@ -255,7 +255,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
255255

256256
if (debugPort == null && debugUri == null) {
257257
if (device is FuchsiaDevice) {
258-
final String module = stringArg('module');
258+
final String module = stringArgDeprecated('module');
259259
if (module == null) {
260260
throwToolExit("'--module' is required for attaching to a Fuchsia device");
261261
}
@@ -370,7 +370,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
370370
signals: globals.signals,
371371
processInfo: globals.processInfo,
372372
reportReady: boolArg('report-ready'),
373-
pidFile: stringArg('pid-file'),
373+
pidFile: stringArgDeprecated('pid-file'),
374374
)
375375
..registerSignalHandlers()
376376
..setupTerminal();
@@ -418,7 +418,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
418418
final FlutterDevice flutterDevice = await FlutterDevice.create(
419419
device,
420420
target: targetFile,
421-
targetModel: TargetModel(stringArg('target-model')),
421+
targetModel: TargetModel(stringArgDeprecated('target-model')),
422422
buildInfo: buildInfo,
423423
userIdentifier: userIdentifier,
424424
platform: globals.platform,
@@ -437,8 +437,8 @@ known, it can be explicitly provided to attach via the command-line, e.g.
437437
target: targetFile,
438438
debuggingOptions: debuggingOptions,
439439
packagesFilePath: globalResults['packages'] as String,
440-
projectRootPath: stringArg('project-root'),
441-
dillOutputPath: stringArg('output-dill'),
440+
projectRootPath: stringArgDeprecated('project-root'),
441+
dillOutputPath: stringArgDeprecated('output-dill'),
442442
ipv6: usesIpv6,
443443
flutterProject: flutterProject,
444444
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand {
112112
final Iterable<AndroidArch> targetArchitectures =
113113
stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName);
114114

115-
final String? buildNumberArg = stringArg('build-number');
115+
final String? buildNumberArg = stringArgDeprecated('build-number');
116116
final String buildNumber = argParser.options.containsKey('build-number')
117117
&& buildNumberArg != null
118118
&& buildNumberArg.isNotEmpty
@@ -142,7 +142,7 @@ class BuildAarCommand extends BuildSubCommand {
142142
project: _getProject(),
143143
target: targetFile.path,
144144
androidBuildInfo: androidBuildInfo,
145-
outputDirectoryPath: stringArg('output-dir'),
145+
outputDirectoryPath: stringArgDeprecated('output-dir'),
146146
buildNumber: buildNumber,
147147
);
148148
return FlutterCommandResult.success();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BuildBundleCommand extends BuildSubCommand {
8080
return const CustomDimensions();
8181
}
8282
return CustomDimensions(
83-
commandBuildBundleTargetPlatform: stringArg('target-platform'),
83+
commandBuildBundleTargetPlatform: stringArgDeprecated('target-platform'),
8484
commandBuildBundleIsModule: flutterProject.isModule,
8585
);
8686
}
@@ -95,7 +95,7 @@ class BuildBundleCommand extends BuildSubCommand {
9595

9696
@override
9797
Future<FlutterCommandResult> runCommand() async {
98-
final String targetPlatform = stringArg('target-platform')!;
98+
final String targetPlatform = stringArgDeprecated('target-platform')!;
9999
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
100100
if (platform == null) {
101101
throwToolExit('Unknown platform: $targetPlatform');
@@ -138,8 +138,8 @@ class BuildBundleCommand extends BuildSubCommand {
138138
platform: platform,
139139
buildInfo: buildInfo,
140140
mainPath: targetFile,
141-
depfilePath: stringArg('depfile'),
142-
assetDirPath: stringArg('asset-dir'),
141+
depfilePath: stringArgDeprecated('depfile'),
142+
assetDirPath: stringArgDeprecated('asset-dir'),
143143
);
144144
return FlutterCommandResult.success();
145145
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class BuildFuchsiaCommand extends BuildSubCommand {
7979
await buildFuchsia(
8080
fuchsiaProject: flutterProject.fuchsia,
8181
target: targetFile,
82-
targetPlatform: getTargetPlatformForName(stringArg('target-platform')!),
82+
targetPlatform: getTargetPlatformForName(stringArgDeprecated('target-platform')!),
8383
buildInfo: buildInfo,
84-
runnerPackageSource: stringArg('runner-source')!,
84+
runnerPackageSource: stringArgDeprecated('runner-source')!,
8585
);
8686
return FlutterCommandResult.success();
8787
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
9898
@override
9999
final bool configOnly = false;
100100

101-
String? get exportOptionsPlist => stringArg('export-options-plist');
101+
String? get exportOptionsPlist => stringArgDeprecated('export-options-plist');
102102

103103
@override
104104
Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs
@@ -153,7 +153,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
153153
final String relativeOutputPath = app.ipaOutputPath;
154154
final String absoluteOutputPath = globals.fs.path.absolute(relativeOutputPath);
155155
final String absoluteArchivePath = globals.fs.path.absolute(app.archiveBundleOutputPath);
156-
final String exportMethod = stringArg('export-method')!;
156+
final String exportMethod = stringArgDeprecated('export-method')!;
157157
final bool isAppStoreUpload = exportMethod == 'app-store';
158158
File? generatedExportPlist;
159159
try {
@@ -241,7 +241,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
241241
''');
242242

243243
plistContents.write('''
244-
<string>${stringArg('export-method')}</string>
244+
<string>${stringArgDeprecated('export-method')}</string>
245245
''');
246246
if (xcodeBuildResult?.xcodeBuildExecution?.buildSettings['ENABLE_BITCODE'] != 'YES') {
247247
// Bitcode is off by default in Flutter iOS apps.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
159159

160160
@override
161161
Future<FlutterCommandResult> runCommand() async {
162-
final String outputArgument = stringArg('output')
162+
final String outputArgument = stringArgDeprecated('output')
163163
?? globals.fs.path.join(globals.fs.currentDirectory.path, 'build', 'ios', 'framework');
164164

165165
if (outputArgument.isEmpty) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BuildLinuxCommand extends BuildSubCommand {
6161
final BuildInfo buildInfo = await getBuildInfo();
6262
final FlutterProject flutterProject = FlutterProject.current();
6363
final TargetPlatform targetPlatform =
64-
getTargetPlatformForName(stringArg('target-platform')!);
64+
getTargetPlatformForName(stringArgDeprecated('target-platform')!);
6565
final bool needCrossBuild =
6666
getNameForHostPlatformArch(_operatingSystemUtils.hostPlatform)
6767
!= getNameForTargetPlatformArch(targetPlatform);
@@ -95,7 +95,7 @@ class BuildLinuxCommand extends BuildSubCommand {
9595
),
9696
needCrossBuild: needCrossBuild,
9797
targetPlatform: targetPlatform,
98-
targetSysroot: stringArg('target-sysroot')!,
98+
targetSysroot: stringArgDeprecated('target-sysroot')!,
9999
);
100100
return FlutterCommandResult.success();
101101
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ class BuildWebCommand extends BuildSubCommand {
9090
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
9191
}
9292
final FlutterProject flutterProject = FlutterProject.current();
93-
final String target = stringArg('target')!;
93+
final String target = stringArgDeprecated('target')!;
9494
final BuildInfo buildInfo = await getBuildInfo();
9595
if (buildInfo.isDebug) {
9696
throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
9797
}
98-
final String? baseHref = stringArg('base-href');
98+
final String? baseHref = stringArgDeprecated('base-href');
9999
if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) {
100100
throwToolExit('base-href should start and end with /');
101101
}
@@ -119,11 +119,11 @@ class BuildWebCommand extends BuildSubCommand {
119119
target,
120120
buildInfo,
121121
boolArg('csp'),
122-
stringArg('pwa-strategy')!,
122+
stringArgDeprecated('pwa-strategy')!,
123123
boolArg('source-maps'),
124124
boolArg('native-null-assertions'),
125125
baseHref,
126-
stringArg('dart2js-optimization'),
126+
stringArgDeprecated('dart2js-optimization'),
127127
);
128128
return FlutterCommandResult.success();
129129
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ class ConfigCommand extends FlutterCommand {
132132
}
133133

134134
if (argResults?.wasParsed('android-sdk') ?? false) {
135-
_updateConfig('android-sdk', stringArg('android-sdk')!);
135+
_updateConfig('android-sdk', stringArgDeprecated('android-sdk')!);
136136
}
137137

138138
if (argResults?.wasParsed('android-studio-dir') ?? false) {
139-
_updateConfig('android-studio-dir', stringArg('android-studio-dir')!);
139+
_updateConfig('android-studio-dir', stringArgDeprecated('android-studio-dir')!);
140140
}
141141

142142
if (argResults?.wasParsed('clear-ios-signing-cert') ?? false) {
143143
_updateConfig('ios-signing-cert', '');
144144
}
145145

146146
if (argResults?.wasParsed('build-dir') ?? false) {
147-
final String buildDir = stringArg('build-dir')!;
147+
final String buildDir = stringArgDeprecated('build-dir')!;
148148
if (globals.fs.path.isAbsolute(buildDir)) {
149149
throwToolExit('build-dir should be a relative path');
150150
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class CreateCommand extends CreateBase {
9393
@override
9494
Future<CustomDimensions> get usageValues async {
9595
return CustomDimensions(
96-
commandCreateProjectType: stringArg('template'),
97-
commandCreateAndroidLanguage: stringArg('android-language'),
98-
commandCreateIosLanguage: stringArg('ios-language'),
96+
commandCreateProjectType: stringArgDeprecated('template'),
97+
commandCreateAndroidLanguage: stringArgDeprecated('android-language'),
98+
commandCreateIosLanguage: stringArgDeprecated('ios-language'),
9999
);
100100
}
101101

@@ -162,7 +162,7 @@ class CreateCommand extends CreateBase {
162162
FlutterProjectType detectedProjectType;
163163
final bool metadataExists = projectDir.absolute.childFile('.metadata').existsSync();
164164
if (argResults['template'] != null) {
165-
template = stringToProjectType(stringArg('template'));
165+
template = stringToProjectType(stringArgDeprecated('template'));
166166
}
167167
// If the project directory exists and isn't empty, then try to determine the template
168168
// type from the project directory.
@@ -190,7 +190,7 @@ class CreateCommand extends CreateBase {
190190
Future<FlutterCommandResult> runCommand() async {
191191
if (argResults['list-samples'] != null) {
192192
// _writeSamplesJson can potentially be long-lived.
193-
await _writeSamplesJson(stringArg('list-samples'));
193+
await _writeSamplesJson(stringArgDeprecated('list-samples'));
194194
return FlutterCommandResult.success();
195195
}
196196

@@ -199,12 +199,12 @@ class CreateCommand extends CreateBase {
199199
String sampleCode;
200200
if (argResults['sample'] != null) {
201201
if (argResults['template'] != null &&
202-
stringToProjectType(stringArg('template') ?? 'app') != FlutterProjectType.app) {
202+
stringToProjectType(stringArgDeprecated('template') ?? 'app') != FlutterProjectType.app) {
203203
throwToolExit('Cannot specify --sample with a project type other than '
204204
'"${flutterProjectTypeToString(FlutterProjectType.app)}"');
205205
}
206206
// Fetch the sample from the server.
207-
sampleCode = await _fetchSampleFromServer(stringArg('sample'));
207+
sampleCode = await _fetchSampleFromServer(stringArgDeprecated('sample'));
208208
}
209209

210210
final FlutterProjectType template = _getProjectType(projectDir);
@@ -276,12 +276,12 @@ class CreateCommand extends CreateBase {
276276
organization: organization,
277277
projectName: projectName,
278278
titleCaseProjectName: titleCaseProjectName,
279-
projectDescription: stringArg('description'),
279+
projectDescription: stringArgDeprecated('description'),
280280
flutterRoot: flutterRoot,
281281
withPlatformChannelPluginHook: generateMethodChannelsPlugin,
282282
withFfiPluginHook: generateFfiPlugin,
283-
androidLanguage: stringArg('android-language'),
284-
iosLanguage: stringArg('ios-language'),
283+
androidLanguage: stringArgDeprecated('android-language'),
284+
iosLanguage: stringArgDeprecated('ios-language'),
285285
iosDevelopmentTeam: developmentTeam,
286286
ios: includeIos,
287287
android: featureFlags.isAndroidEnabled && platforms.contains('android'),
@@ -438,7 +438,7 @@ Your $application code is in $relativeAppMain.
438438
}) async {
439439
int generatedCount = 0;
440440
final String description = argResults.wasParsed('description')
441-
? stringArg('description')
441+
? stringArgDeprecated('description')
442442
: 'A new Flutter module project.';
443443
templateContext['description'] = description;
444444
generatedCount += await renderTemplate(
@@ -472,7 +472,7 @@ Your $application code is in $relativeAppMain.
472472
}) async {
473473
int generatedCount = 0;
474474
final String description = argResults.wasParsed('description')
475-
? stringArg('description')
475+
? stringArgDeprecated('description')
476476
: 'A new Flutter package project.';
477477
templateContext['description'] = description;
478478
generatedCount += await renderTemplate(
@@ -518,7 +518,7 @@ Your $application code is in $relativeAppMain.
518518
templateContext['no_platforms'] = !willAddPlatforms;
519519
int generatedCount = 0;
520520
final String description = argResults.wasParsed('description')
521-
? stringArg('description')
521+
? stringArgDeprecated('description')
522522
: 'A new Flutter plugin project.';
523523
templateContext['description'] = description;
524524
generatedCount += await renderMerged(
@@ -597,7 +597,7 @@ Your $application code is in $relativeAppMain.
597597
templateContext['no_platforms'] = !willAddPlatforms;
598598
int generatedCount = 0;
599599
final String description = argResults.wasParsed('description')
600-
? stringArg('description')
600+
? stringArgDeprecated('description')
601601
: 'A new Flutter FFI plugin project.';
602602
templateContext['description'] = description;
603603
generatedCount += await renderMerged(

0 commit comments

Comments
 (0)