Skip to content

Commit

Permalink
[flutter_tools] stringArg refactor (#103231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasguerrero committed May 9, 2022
1 parent 9511638 commit 596e9d1
Show file tree
Hide file tree
Showing 29 changed files with 195 additions and 160 deletions.
10 changes: 5 additions & 5 deletions packages/flutter_tools/lib/src/commands/assemble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class AssembleCommand extends FlutterCommand {
/// The environmental configuration for a build invocation.
Environment createEnvironment() {
final FlutterProject flutterProject = FlutterProject.current();
String? output = stringArg('output');
String? output = stringArgDeprecated('output');
if (output == null) {
throwToolExit('--output directory is required for assemble.');
}
Expand Down Expand Up @@ -318,7 +318,7 @@ class AssembleCommand extends FlutterCommand {
environment,
buildSystemConfig: BuildSystemConfig(
resourcePoolSize: argumentResults.wasParsed('resource-pool-size')
? int.tryParse(stringArg('resource-pool-size')!)
? int.tryParse(stringArgDeprecated('resource-pool-size')!)
: null,
),
);
Expand All @@ -335,17 +335,17 @@ class AssembleCommand extends FlutterCommand {
globals.printTrace('build succeeded.');

if (argumentResults.wasParsed('build-inputs')) {
writeListIfChanged(result.inputFiles, stringArg('build-inputs')!);
writeListIfChanged(result.inputFiles, stringArgDeprecated('build-inputs')!);
}
if (argumentResults.wasParsed('build-outputs')) {
writeListIfChanged(result.outputFiles, stringArg('build-outputs')!);
writeListIfChanged(result.outputFiles, stringArgDeprecated('build-outputs')!);
}
if (argumentResults.wasParsed('performance-measurement-file')) {
final File outFile = globals.fs.file(argumentResults['performance-measurement-file']);
writePerformanceData(result.performance.values, outFile);
}
if (argumentResults.wasParsed('depfile')) {
final File depfileFile = globals.fs.file(stringArg('depfile'));
final File depfileFile = globals.fs.file(stringArgDeprecated('depfile'));
final Depfile depfile = Depfile(result.inputFiles, result.outputFiles);
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
Expand Down
20 changes: 10 additions & 10 deletions packages/flutter_tools/lib/src/commands/attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
return null;
}
try {
return int.parse(stringArg('debug-port'));
return int.parse(stringArgDeprecated('debug-port'));
} on Exception catch (error) {
throwToolExit('Invalid port for `--debug-port`: $error');
}
Expand All @@ -163,9 +163,9 @@ known, it can be explicitly provided to attach via the command-line, e.g.
if (argResults['debug-url'] == null) {
return null;
}
final Uri uri = Uri.tryParse(stringArg('debug-url'));
final Uri uri = Uri.tryParse(stringArgDeprecated('debug-url'));
if (uri == null) {
throwToolExit('Invalid `--debug-url`: ${stringArg('debug-url')}');
throwToolExit('Invalid `--debug-url`: ${stringArgDeprecated('debug-url')}');
}
if (!uri.hasPort) {
throwToolExit('Port not specified for `--debug-url`: $uri');
Expand All @@ -174,10 +174,10 @@ known, it can be explicitly provided to attach via the command-line, e.g.
}

String get appId {
return stringArg('app-id');
return stringArgDeprecated('app-id');
}

String get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
String get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser);

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

if (debugPort == null && debugUri == null) {
if (device is FuchsiaDevice) {
final String module = stringArg('module');
final String module = stringArgDeprecated('module');
if (module == null) {
throwToolExit("'--module' is required for attaching to a Fuchsia device");
}
Expand Down Expand Up @@ -370,7 +370,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
signals: globals.signals,
processInfo: globals.processInfo,
reportReady: boolArg('report-ready'),
pidFile: stringArg('pid-file'),
pidFile: stringArgDeprecated('pid-file'),
)
..registerSignalHandlers()
..setupTerminal();
Expand Down Expand Up @@ -418,7 +418,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
final FlutterDevice flutterDevice = await FlutterDevice.create(
device,
target: targetFile,
targetModel: TargetModel(stringArg('target-model')),
targetModel: TargetModel(stringArgDeprecated('target-model')),
buildInfo: buildInfo,
userIdentifier: userIdentifier,
platform: globals.platform,
Expand All @@ -437,8 +437,8 @@ known, it can be explicitly provided to attach via the command-line, e.g.
target: targetFile,
debuggingOptions: debuggingOptions,
packagesFilePath: globalResults['packages'] as String,
projectRootPath: stringArg('project-root'),
dillOutputPath: stringArg('output-dill'),
projectRootPath: stringArgDeprecated('project-root'),
dillOutputPath: stringArgDeprecated('output-dill'),
ipv6: usesIpv6,
flutterProject: flutterProject,
)
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/build_aar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand {
final Iterable<AndroidArch> targetArchitectures =
stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName);

final String? buildNumberArg = stringArg('build-number');
final String? buildNumberArg = stringArgDeprecated('build-number');
final String buildNumber = argParser.options.containsKey('build-number')
&& buildNumberArg != null
&& buildNumberArg.isNotEmpty
Expand Down Expand Up @@ -142,7 +142,7 @@ class BuildAarCommand extends BuildSubCommand {
project: _getProject(),
target: targetFile.path,
androidBuildInfo: androidBuildInfo,
outputDirectoryPath: stringArg('output-dir'),
outputDirectoryPath: stringArgDeprecated('output-dir'),
buildNumber: buildNumber,
);
return FlutterCommandResult.success();
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/commands/build_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BuildBundleCommand extends BuildSubCommand {
return const CustomDimensions();
}
return CustomDimensions(
commandBuildBundleTargetPlatform: stringArg('target-platform'),
commandBuildBundleTargetPlatform: stringArgDeprecated('target-platform'),
commandBuildBundleIsModule: flutterProject.isModule,
);
}
Expand All @@ -95,7 +95,7 @@ class BuildBundleCommand extends BuildSubCommand {

@override
Future<FlutterCommandResult> runCommand() async {
final String targetPlatform = stringArg('target-platform')!;
final String targetPlatform = stringArgDeprecated('target-platform')!;
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
if (platform == null) {
throwToolExit('Unknown platform: $targetPlatform');
Expand Down Expand Up @@ -138,8 +138,8 @@ class BuildBundleCommand extends BuildSubCommand {
platform: platform,
buildInfo: buildInfo,
mainPath: targetFile,
depfilePath: stringArg('depfile'),
assetDirPath: stringArg('asset-dir'),
depfilePath: stringArgDeprecated('depfile'),
assetDirPath: stringArgDeprecated('asset-dir'),
);
return FlutterCommandResult.success();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/build_fuchsia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class BuildFuchsiaCommand extends BuildSubCommand {
await buildFuchsia(
fuchsiaProject: flutterProject.fuchsia,
target: targetFile,
targetPlatform: getTargetPlatformForName(stringArg('target-platform')!),
targetPlatform: getTargetPlatformForName(stringArgDeprecated('target-platform')!),
buildInfo: buildInfo,
runnerPackageSource: stringArg('runner-source')!,
runnerPackageSource: stringArgDeprecated('runner-source')!,
);
return FlutterCommandResult.success();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_tools/lib/src/commands/build_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
@override
final bool configOnly = false;

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

@override
Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs
Expand Down Expand Up @@ -153,7 +153,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
final String relativeOutputPath = app.ipaOutputPath;
final String absoluteOutputPath = globals.fs.path.absolute(relativeOutputPath);
final String absoluteArchivePath = globals.fs.path.absolute(app.archiveBundleOutputPath);
final String exportMethod = stringArg('export-method')!;
final String exportMethod = stringArgDeprecated('export-method')!;
final bool isAppStoreUpload = exportMethod == 'app-store';
File? generatedExportPlist;
try {
Expand Down Expand Up @@ -241,7 +241,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
''');

plistContents.write('''
<string>${stringArg('export-method')}</string>
<string>${stringArgDeprecated('export-method')}</string>
''');
if (xcodeBuildResult?.xcodeBuildExecution?.buildSettings['ENABLE_BITCODE'] != 'YES') {
// Bitcode is off by default in Flutter iOS apps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {

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

if (outputArgument.isEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/build_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BuildLinuxCommand extends BuildSubCommand {
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
final TargetPlatform targetPlatform =
getTargetPlatformForName(stringArg('target-platform')!);
getTargetPlatformForName(stringArgDeprecated('target-platform')!);
final bool needCrossBuild =
getNameForHostPlatformArch(_operatingSystemUtils.hostPlatform)
!= getNameForTargetPlatformArch(targetPlatform);
Expand Down Expand Up @@ -95,7 +95,7 @@ class BuildLinuxCommand extends BuildSubCommand {
),
needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot')!,
targetSysroot: stringArgDeprecated('target-sysroot')!,
);
return FlutterCommandResult.success();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/commands/build_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class BuildWebCommand extends BuildSubCommand {
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
}
final FlutterProject flutterProject = FlutterProject.current();
final String target = stringArg('target')!;
final String target = stringArgDeprecated('target')!;
final BuildInfo buildInfo = await getBuildInfo();
if (buildInfo.isDebug) {
throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
}
final String? baseHref = stringArg('base-href');
final String? baseHref = stringArgDeprecated('base-href');
if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) {
throwToolExit('base-href should start and end with /');
}
Expand All @@ -119,11 +119,11 @@ class BuildWebCommand extends BuildSubCommand {
target,
buildInfo,
boolArg('csp'),
stringArg('pwa-strategy')!,
stringArgDeprecated('pwa-strategy')!,
boolArg('source-maps'),
boolArg('native-null-assertions'),
baseHref,
stringArg('dart2js-optimization'),
stringArgDeprecated('dart2js-optimization'),
);
return FlutterCommandResult.success();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_tools/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ class ConfigCommand extends FlutterCommand {
}

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

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

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

if (argResults?.wasParsed('build-dir') ?? false) {
final String buildDir = stringArg('build-dir')!;
final String buildDir = stringArgDeprecated('build-dir')!;
if (globals.fs.path.isAbsolute(buildDir)) {
throwToolExit('build-dir should be a relative path');
}
Expand Down
28 changes: 14 additions & 14 deletions packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class CreateCommand extends CreateBase {
@override
Future<CustomDimensions> get usageValues async {
return CustomDimensions(
commandCreateProjectType: stringArg('template'),
commandCreateAndroidLanguage: stringArg('android-language'),
commandCreateIosLanguage: stringArg('ios-language'),
commandCreateProjectType: stringArgDeprecated('template'),
commandCreateAndroidLanguage: stringArgDeprecated('android-language'),
commandCreateIosLanguage: stringArgDeprecated('ios-language'),
);
}

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

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

final FlutterProjectType template = _getProjectType(projectDir);
Expand Down Expand Up @@ -276,12 +276,12 @@ class CreateCommand extends CreateBase {
organization: organization,
projectName: projectName,
titleCaseProjectName: titleCaseProjectName,
projectDescription: stringArg('description'),
projectDescription: stringArgDeprecated('description'),
flutterRoot: flutterRoot,
withPlatformChannelPluginHook: generateMethodChannelsPlugin,
withFfiPluginHook: generateFfiPlugin,
androidLanguage: stringArg('android-language'),
iosLanguage: stringArg('ios-language'),
androidLanguage: stringArgDeprecated('android-language'),
iosLanguage: stringArgDeprecated('ios-language'),
iosDevelopmentTeam: developmentTeam,
ios: includeIos,
android: featureFlags.isAndroidEnabled && platforms.contains('android'),
Expand Down Expand Up @@ -438,7 +438,7 @@ Your $application code is in $relativeAppMain.
}) async {
int generatedCount = 0;
final String description = argResults.wasParsed('description')
? stringArg('description')
? stringArgDeprecated('description')
: 'A new Flutter module project.';
templateContext['description'] = description;
generatedCount += await renderTemplate(
Expand Down Expand Up @@ -472,7 +472,7 @@ Your $application code is in $relativeAppMain.
}) async {
int generatedCount = 0;
final String description = argResults.wasParsed('description')
? stringArg('description')
? stringArgDeprecated('description')
: 'A new Flutter package project.';
templateContext['description'] = description;
generatedCount += await renderTemplate(
Expand Down Expand Up @@ -518,7 +518,7 @@ Your $application code is in $relativeAppMain.
templateContext['no_platforms'] = !willAddPlatforms;
int generatedCount = 0;
final String description = argResults.wasParsed('description')
? stringArg('description')
? stringArgDeprecated('description')
: 'A new Flutter plugin project.';
templateContext['description'] = description;
generatedCount += await renderMerged(
Expand Down Expand Up @@ -597,7 +597,7 @@ Your $application code is in $relativeAppMain.
templateContext['no_platforms'] = !willAddPlatforms;
int generatedCount = 0;
final String description = argResults.wasParsed('description')
? stringArg('description')
? stringArgDeprecated('description')
: 'A new Flutter FFI plugin project.';
templateContext['description'] = description;
generatedCount += await renderMerged(
Expand Down
Loading

0 comments on commit 596e9d1

Please sign in to comment.