diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index 0631b428fa..8a5398e5fc 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -125,7 +125,7 @@ class AnalyzeCommand extends FlutterCommand { @override bool get shouldRunPub { // If they're not analyzing the current project. - if (!boolArgDeprecated('current-package')) { + if (!boolArg('current-package')) { return false; } @@ -135,7 +135,7 @@ class AnalyzeCommand extends FlutterCommand { } // Don't run pub if asking for machine output. - if (boolArg('machine') != null && boolArg('machine')!) { + if (boolArg('machine')) { return false; } @@ -144,12 +144,9 @@ class AnalyzeCommand extends FlutterCommand { @override Future runCommand() async { - final bool? suggestionFlag = boolArg('suggestions'); - final bool machineFlag = boolArg('machine') ?? false; - if (suggestionFlag != null && suggestionFlag == true) { + if (boolArg('suggestions')) { final String directoryPath; - final bool? watchFlag = boolArg('watch'); - if (watchFlag != null && watchFlag) { + if (boolArg('watch')) { throwToolExit('flag --watch is not compatible with --suggestions'); } if (workingDirectory == null) { @@ -171,9 +168,9 @@ class AnalyzeCommand extends FlutterCommand { allProjectValidators: _allProjectValidators, userPath: directoryPath, processManager: _processManager, - machine: machineFlag, + machine: boolArg('machine'), ).run(); - } else if (boolArgDeprecated('watch')) { + } else if (boolArg('watch')) { await AnalyzeContinuously( argResults!, runner!.getRepoRoots(), diff --git a/packages/flutter_tools/lib/src/commands/assemble.dart b/packages/flutter_tools/lib/src/commands/assemble.dart index 29d9623217..42b54a3338 100644 --- a/packages/flutter_tools/lib/src/commands/assemble.dart +++ b/packages/flutter_tools/lib/src/commands/assemble.dart @@ -209,7 +209,7 @@ class AssembleCommand extends FlutterCommand { /// The environmental configuration for a build invocation. Environment createEnvironment() { final FlutterProject flutterProject = FlutterProject.current(); - String? output = stringArgDeprecated('output'); + String? output = stringArg('output'); if (output == null) { throwToolExit('--output directory is required for assemble.'); } @@ -317,7 +317,7 @@ class AssembleCommand extends FlutterCommand { environment, buildSystemConfig: BuildSystemConfig( resourcePoolSize: argumentResults.wasParsed('resource-pool-size') - ? int.tryParse(stringArgDeprecated('resource-pool-size')!) + ? int.tryParse(stringArg('resource-pool-size')!) : null, ), ); @@ -334,17 +334,17 @@ class AssembleCommand extends FlutterCommand { globals.printTrace('build succeeded.'); if (argumentResults.wasParsed('build-inputs')) { - writeListIfChanged(result.inputFiles, stringArgDeprecated('build-inputs')!); + writeListIfChanged(result.inputFiles, stringArg('build-inputs')!); } if (argumentResults.wasParsed('build-outputs')) { - writeListIfChanged(result.outputFiles, stringArgDeprecated('build-outputs')!); + writeListIfChanged(result.outputFiles, stringArg('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(stringArgDeprecated('depfile')); + final File depfileFile = globals.fs.file(stringArg('depfile')); final Depfile depfile = Depfile(result.inputFiles, result.outputFiles); final DepfileService depfileService = DepfileService( fileSystem: globals.fs, diff --git a/packages/flutter_tools/lib/src/commands/attach.dart b/packages/flutter_tools/lib/src/commands/attach.dart index 6469f29098..b3dd7bfd40 100644 --- a/packages/flutter_tools/lib/src/commands/attach.dart +++ b/packages/flutter_tools/lib/src/commands/attach.dart @@ -181,19 +181,20 @@ known, it can be explicitly provided to attach via the command-line, e.g. return null; } try { - return int.parse(stringArgDeprecated('debug-port')!); + return int.parse(stringArg('debug-port')!); } on Exception catch (error) { throwToolExit('Invalid port for `--debug-port`: $error'); } } Uri? get debugUri { - if (argResults!['debug-url'] == null) { + final String? debugUrl = stringArg('debug-url'); + if (debugUrl == null) { return null; } - final Uri? uri = Uri.tryParse(stringArgDeprecated('debug-url')!); + final Uri? uri = Uri.tryParse(debugUrl); if (uri == null) { - throwToolExit('Invalid `--debug-url`: ${stringArgDeprecated('debug-url')}'); + throwToolExit('Invalid `--debug-url`: $debugUrl'); } if (!uri.hasPort) { throwToolExit('Port not specified for `--debug-url`: $uri'); @@ -201,13 +202,13 @@ known, it can be explicitly provided to attach via the command-line, e.g. return uri; } - bool get serveObservatory => boolArg('serve-observatory') ?? false; + bool get serveObservatory => boolArg('serve-observatory'); String? get appId { - return stringArgDeprecated('app-id'); + return stringArg('app-id'); } - String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser); @override Future validateCommand() async { @@ -268,7 +269,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. Future _attachToDevice(Device device) async { final FlutterProject flutterProject = FlutterProject.current(); - final Daemon? daemon = boolArgDeprecated('machine') + final Daemon? daemon = boolArg('machine') ? Daemon( DaemonConnection( daemonStreams: DaemonStreams.fromStdio(_stdio, logger: _logger), @@ -290,7 +291,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. if ((debugPort == null && debugUri == null) || isNetworkDevice) { if (device is FuchsiaDevice) { - final String? module = stringArgDeprecated('module'); + final String? module = stringArg('module'); if (module == null) { throwToolExit("'--module' is required for attaching to a Fuchsia device"); } @@ -428,7 +429,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. connectionInfoCompleter: connectionInfoCompleter, appStartedCompleter: appStartedCompleter, allowExistingDdsInstance: true, - enableDevTools: boolArgDeprecated(FlutterCommand.kEnableDevTools), + enableDevTools: boolArg(FlutterCommand.kEnableDevTools), ); }, device, @@ -460,8 +461,8 @@ known, it can be explicitly provided to attach via the command-line, e.g. terminal: _terminal, signals: _signals, processInfo: _processInfo, - reportReady: boolArgDeprecated('report-ready'), - pidFile: stringArgDeprecated('pid-file'), + reportReady: boolArg('report-ready'), + pidFile: stringArg('pid-file'), ) ..registerSignalHandlers() ..setupTerminal(); @@ -469,7 +470,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. result = await runner.attach( appStartedCompleter: onAppStart, allowExistingDdsInstance: true, - enableDevTools: boolArgDeprecated(FlutterCommand.kEnableDevTools), + enableDevTools: boolArg(FlutterCommand.kEnableDevTools), ); if (result != 0) { throwToolExit(null, exitCode: result); @@ -505,7 +506,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(stringArgDeprecated('target-model')!), + targetModel: TargetModel(stringArg('target-model')!), buildInfo: buildInfo, userIdentifier: userIdentifier, platform: _platform, @@ -526,8 +527,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: stringArgDeprecated('project-root'), - dillOutputPath: stringArgDeprecated('output-dill'), + projectRootPath: stringArg('project-root'), + dillOutputPath: stringArg('output-dill'), ipv6: usesIpv6, flutterProject: flutterProject, ) diff --git a/packages/flutter_tools/lib/src/commands/build_aar.dart b/packages/flutter_tools/lib/src/commands/build_aar.dart index c8419f0f2d..c1144118d7 100644 --- a/packages/flutter_tools/lib/src/commands/build_aar.dart +++ b/packages/flutter_tools/lib/src/commands/build_aar.dart @@ -6,7 +6,6 @@ import '../android/android_builder.dart'; import '../android/android_sdk.dart'; import '../android/gradle_utils.dart'; import '../base/common.dart'; - import '../base/file_system.dart'; import '../base/os.dart'; import '../build_info.dart'; @@ -113,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand { final Iterable targetArchitectures = stringsArg('target-platform').map(getAndroidArchForName); - final String? buildNumberArg = stringArgDeprecated('build-number'); + final String? buildNumberArg = stringArg('build-number'); final String buildNumber = argParser.options.containsKey('build-number') && buildNumberArg != null && buildNumberArg.isNotEmpty @@ -122,7 +121,7 @@ class BuildAarCommand extends BuildSubCommand { final File targetFile = _fileSystem.file(_fileSystem.path.join('lib', 'main.dart')); for (final String buildMode in const ['debug', 'profile', 'release']) { - if (boolArgDeprecated(buildMode)) { + if (boolArg(buildMode)) { androidBuildInfo.add( AndroidBuildInfo( await getBuildInfo( diff --git a/packages/flutter_tools/lib/src/commands/build_apk.dart b/packages/flutter_tools/lib/src/commands/build_apk.dart index 7402169814..d255d4dd68 100644 --- a/packages/flutter_tools/lib/src/commands/build_apk.dart +++ b/packages/flutter_tools/lib/src/commands/build_apk.dart @@ -58,9 +58,9 @@ class BuildApkCommand extends BuildSubCommand { final String name = 'apk'; @override - DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit; + DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit; - bool get configOnly => boolArg('config-only') ?? false; + bool get configOnly => boolArg('config-only'); @override Future> get requiredArtifacts async => { @@ -80,11 +80,11 @@ class BuildApkCommand extends BuildSubCommand { Future get usageValues async { String buildMode; - if (boolArgDeprecated('release')) { + if (boolArg('release')) { buildMode = 'release'; - } else if (boolArgDeprecated('debug')) { + } else if (boolArg('debug')) { buildMode = 'debug'; - } else if (boolArgDeprecated('profile')) { + } else if (boolArg('profile')) { buildMode = 'profile'; } else { // The build defaults to release. @@ -94,7 +94,7 @@ class BuildApkCommand extends BuildSubCommand { return CustomDimensions( commandBuildApkTargetPlatform: stringsArg('target-platform').join(','), commandBuildApkBuildMode: buildMode, - commandBuildApkSplitPerAbi: boolArgDeprecated('split-per-abi'), + commandBuildApkSplitPerAbi: boolArg('split-per-abi'), ); } @@ -106,9 +106,9 @@ class BuildApkCommand extends BuildSubCommand { final BuildInfo buildInfo = await getBuildInfo(); final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo( buildInfo, - splitPerAbi: boolArgDeprecated('split-per-abi'), + splitPerAbi: boolArg('split-per-abi'), targetArchs: stringsArg('target-platform').map(getAndroidArchForName), - multidexEnabled: boolArgDeprecated('multidex'), + multidexEnabled: boolArg('multidex'), ); validateBuild(androidBuildInfo); displayNullSafetyMode(androidBuildInfo.buildInfo); diff --git a/packages/flutter_tools/lib/src/commands/build_appbundle.dart b/packages/flutter_tools/lib/src/commands/build_appbundle.dart index d40d3da9ba..742e544818 100644 --- a/packages/flutter_tools/lib/src/commands/build_appbundle.dart +++ b/packages/flutter_tools/lib/src/commands/build_appbundle.dart @@ -70,7 +70,7 @@ class BuildAppBundleCommand extends BuildSubCommand { final String name = 'appbundle'; @override - DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit; + DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit; @override Future> get requiredArtifacts async => { @@ -88,11 +88,11 @@ class BuildAppBundleCommand extends BuildSubCommand { Future get usageValues async { String buildMode; - if (boolArgDeprecated('release')) { + if (boolArg('release')) { buildMode = 'release'; - } else if (boolArgDeprecated('debug')) { + } else if (boolArg('debug')) { buildMode = 'debug'; - } else if (boolArgDeprecated('profile')) { + } else if (boolArg('profile')) { buildMode = 'profile'; } else { // The build defaults to release. @@ -113,12 +113,12 @@ class BuildAppBundleCommand extends BuildSubCommand { final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(await getBuildInfo(), targetArchs: stringsArg('target-platform').map(getAndroidArchForName), - multidexEnabled: boolArgDeprecated('multidex'), + multidexEnabled: boolArg('multidex'), ); // Do all setup verification that doesn't involve loading units. Checks that // require generated loading units are done after gen_snapshot in assemble. final List? deferredComponents = FlutterProject.current().manifest.deferredComponents; - if (deferredComponents != null && boolArgDeprecated('deferred-components') && boolArgDeprecated('validate-deferred-components') && !boolArgDeprecated('debug')) { + if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) { final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator( FlutterProject.current().directory, globals.logger, @@ -154,8 +154,8 @@ class BuildAppBundleCommand extends BuildSubCommand { project: FlutterProject.current(), target: targetFile, androidBuildInfo: androidBuildInfo, - validateDeferredComponents: boolArgDeprecated('validate-deferred-components'), - deferredComponentsEnabled: boolArgDeprecated('deferred-components') && !boolArgDeprecated('debug'), + validateDeferredComponents: boolArg('validate-deferred-components'), + deferredComponentsEnabled: boolArg('deferred-components') && !boolArg('debug'), ); return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/lib/src/commands/build_bundle.dart b/packages/flutter_tools/lib/src/commands/build_bundle.dart index 8ea6e72f72..bece84cf98 100644 --- a/packages/flutter_tools/lib/src/commands/build_bundle.dart +++ b/packages/flutter_tools/lib/src/commands/build_bundle.dart @@ -78,14 +78,14 @@ class BuildBundleCommand extends BuildSubCommand { final String projectDir = globals.fs.file(targetFile).parent.parent.path; final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectDir)); return CustomDimensions( - commandBuildBundleTargetPlatform: stringArgDeprecated('target-platform'), + commandBuildBundleTargetPlatform: stringArg('target-platform'), commandBuildBundleIsModule: flutterProject.isModule, ); } @override Future validateCommand() async { - if (boolArgDeprecated('tree-shake-icons')) { + if (boolArg('tree-shake-icons')) { throwToolExit('The "--tree-shake-icons" flag is deprecated for "build bundle" and will be removed in a future version of Flutter.'); } return super.validateCommand(); @@ -93,7 +93,7 @@ class BuildBundleCommand extends BuildSubCommand { @override Future runCommand() async { - final String targetPlatform = stringArgDeprecated('target-platform')!; + final String targetPlatform = stringArg('target-platform')!; final TargetPlatform platform = getTargetPlatformForName(targetPlatform); // Check for target platforms that are only allowed via feature flags. switch (platform) { @@ -133,8 +133,8 @@ class BuildBundleCommand extends BuildSubCommand { platform: platform, buildInfo: buildInfo, mainPath: targetFile, - depfilePath: stringArgDeprecated('depfile'), - assetDirPath: stringArgDeprecated('asset-dir'), + depfilePath: stringArg('depfile'), + assetDirPath: stringArg('asset-dir'), ); return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/lib/src/commands/build_ios.dart b/packages/flutter_tools/lib/src/commands/build_ios.dart index 9b8c2c266f..d3a7eb079c 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios.dart @@ -49,10 +49,10 @@ class BuildIOSCommand extends _BuildIOSSubCommand { final XcodeBuildAction xcodeBuildAction = XcodeBuildAction.build; @override - EnvironmentType get environmentType => boolArgDeprecated('simulator') ? EnvironmentType.simulator : EnvironmentType.physical; + EnvironmentType get environmentType => boolArg('simulator') ? EnvironmentType.simulator : EnvironmentType.physical; @override - bool get configOnly => boolArgDeprecated('config-only'); + bool get configOnly => boolArg('config-only'); @override Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs.directory(xcodeResultOutput).parent; @@ -131,7 +131,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { @override final bool configOnly = false; - String? get exportOptionsPlist => stringArgDeprecated('export-options-plist'); + String? get exportOptionsPlist => stringArg('export-options-plist'); @override Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs @@ -455,7 +455,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 = stringArgDeprecated('export-method')!; + final String exportMethod = stringArg('export-method')!; final bool isAppStoreUpload = exportMethod == 'app-store'; File? generatedExportPlist; try { @@ -540,7 +540,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { method - ${stringArgDeprecated('export-method')} + ${stringArg('export-method')} uploadBitcode @@ -596,7 +596,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { EnvironmentType get environmentType; bool get configOnly; - bool get shouldCodesign => boolArgDeprecated('codesign'); + bool get shouldCodesign => boolArg('codesign'); late final Future cachedBuildInfo = getBuildInfo(); diff --git a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart index 31ae2b6034..69ee07c960 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart @@ -109,13 +109,13 @@ abstract class BuildFrameworkCommand extends BuildSubCommand { Future> getBuildInfos() async { final List buildInfos = []; - if (boolArgDeprecated('debug')) { + if (boolArg('debug')) { buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.debug)); } - if (boolArgDeprecated('profile')) { + if (boolArg('profile')) { buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.profile)); } - if (boolArgDeprecated('release')) { + if (boolArg('release')) { buildInfos.add(await getBuildInfo(forcedBuildMode: BuildMode.release)); } @@ -216,14 +216,14 @@ class BuildIOSFrameworkCommand extends BuildFrameworkCommand { Future validateCommand() async { await super.validateCommand(); - if (boolArgDeprecated('universal')) { + if (boolArg('universal')) { throwToolExit('--universal has been deprecated, only XCFrameworks are supported.'); } } @override Future runCommand() async { - final String outputArgument = stringArgDeprecated('output') + final String outputArgument = stringArg('output') ?? globals.fs.path.join(globals.fs.currentDirectory.path, 'build', 'ios', 'framework'); if (outputArgument.isEmpty) { @@ -247,8 +247,8 @@ class BuildIOSFrameworkCommand extends BuildFrameworkCommand { modeDirectory.deleteSync(recursive: true); } - if (boolArgDeprecated('cocoapods')) { - produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArgDeprecated('force')); + if (boolArg('cocoapods')) { + produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force')); } else { // Copy Flutter.xcframework. await _produceFlutterFramework(buildInfo, modeDirectory); @@ -496,7 +496,7 @@ end 'SYMROOT=${iPhoneBuildOutput.path}', 'ONLY_ACTIVE_ARCH=NO', // No device targeted, so build all valid architectures. 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', - if (boolArg('static') ?? false) + if (boolArg('static')) 'MACH_O_TYPE=staticlib', ]; @@ -522,7 +522,7 @@ end 'SYMROOT=${simulatorBuildOutput.path}', 'ONLY_ACTIVE_ARCH=NO', // No device targeted, so build all valid architectures. 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', - if (boolArg('static') ?? false) + if (boolArg('static')) 'MACH_O_TYPE=staticlib', ]; diff --git a/packages/flutter_tools/lib/src/commands/build_linux.dart b/packages/flutter_tools/lib/src/commands/build_linux.dart index 8f13601eb4..b96810437b 100644 --- a/packages/flutter_tools/lib/src/commands/build_linux.dart +++ b/packages/flutter_tools/lib/src/commands/build_linux.dart @@ -60,7 +60,7 @@ class BuildLinuxCommand extends BuildSubCommand { final BuildInfo buildInfo = await getBuildInfo(); final FlutterProject flutterProject = FlutterProject.current(); final TargetPlatform targetPlatform = - getTargetPlatformForName(stringArgDeprecated('target-platform')!); + getTargetPlatformForName(stringArg('target-platform')!); final bool needCrossBuild = getNameForHostPlatformArch(_operatingSystemUtils.hostPlatform) != getNameForTargetPlatformArch(targetPlatform); @@ -94,7 +94,7 @@ class BuildLinuxCommand extends BuildSubCommand { ), needCrossBuild: needCrossBuild, targetPlatform: targetPlatform, - targetSysroot: stringArgDeprecated('target-sysroot')!, + targetSysroot: stringArg('target-sysroot')!, ); return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/lib/src/commands/build_macos.dart b/packages/flutter_tools/lib/src/commands/build_macos.dart index a6efb70fec..091afbdabc 100644 --- a/packages/flutter_tools/lib/src/commands/build_macos.dart +++ b/packages/flutter_tools/lib/src/commands/build_macos.dart @@ -46,7 +46,7 @@ class BuildMacosCommand extends BuildSubCommand { @override bool get supported => globals.platform.isMacOS; - bool get configOnly => boolArgDeprecated('config-only'); + bool get configOnly => boolArg('config-only'); @override Future runCommand() async { diff --git a/packages/flutter_tools/lib/src/commands/build_macos_framework.dart b/packages/flutter_tools/lib/src/commands/build_macos_framework.dart index b36ae0fd68..e229533e22 100644 --- a/packages/flutter_tools/lib/src/commands/build_macos_framework.dart +++ b/packages/flutter_tools/lib/src/commands/build_macos_framework.dart @@ -80,8 +80,8 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand { modeDirectory.deleteSync(recursive: true); } - if (boolArg('cocoapods') ?? false) { - produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force') ?? false); + if (boolArg('cocoapods')) { + produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force')); } // Build aot, create App.framework and copy FlutterMacOS.framework. Make XCFrameworks. @@ -240,7 +240,7 @@ end final Directory flutterFramework = outputBuildDirectory.childDirectory('FlutterMacOS.framework'); // If FlutterMacOS.podspec was generated, do not generate XCFramework. - if (!(boolArg('cocoapods') ?? false)) { + if (!boolArg('cocoapods')) { await BuildFrameworkCommand.produceXCFramework( [flutterFramework], 'FlutterMacOS', @@ -269,7 +269,7 @@ end 'SYMROOT=${buildOutput.path}', 'ONLY_ACTIVE_ARCH=NO', // No device targeted, so build all valid architectures. 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', - if (boolArg('static') ?? false) 'MACH_O_TYPE=staticlib', + if (boolArg('static')) 'MACH_O_TYPE=staticlib', ]; final RunResult buildPluginsResult = await globals.processUtils.run( diff --git a/packages/flutter_tools/lib/src/commands/build_web.dart b/packages/flutter_tools/lib/src/commands/build_web.dart index 0011c91f16..f8ca2c5f23 100644 --- a/packages/flutter_tools/lib/src/commands/build_web.dart +++ b/packages/flutter_tools/lib/src/commands/build_web.dart @@ -132,18 +132,18 @@ class BuildWebCommand extends BuildSubCommand { throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".'); } - final bool wasmRequested = boolArg('wasm')!; + final bool wasmRequested = boolArg('wasm'); if (wasmRequested && !featureFlags.isFlutterWebWasmEnabled) { throwToolExit('Compiling to WebAssembly (wasm) is only available on the master channel.'); } final FlutterProject flutterProject = FlutterProject.current(); - final String target = stringArgDeprecated('target')!; + final String target = stringArg('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 = stringArgDeprecated('base-href'); + final String? baseHref = stringArg('base-href'); if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) { throwToolExit('base-href should start and end with /'); } @@ -171,16 +171,16 @@ class BuildWebCommand extends BuildSubCommand { flutterProject, target, buildInfo, - boolArgDeprecated('csp'), - stringArgDeprecated('pwa-strategy')!, - boolArgDeprecated('source-maps'), - boolArgDeprecated('native-null-assertions'), + boolArg('csp'), + stringArg('pwa-strategy')!, + boolArg('source-maps'), + boolArg('native-null-assertions'), wasmRequested, baseHref: baseHref, - dart2jsOptimization: stringArgDeprecated('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel, + dart2jsOptimization: stringArg('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel, outputDirectoryPath: outputDirectoryPath, - dumpInfo: boolArgDeprecated('dump-info'), - noFrequencyBasedMinification: boolArgDeprecated('no-frequency-based-minification'), + dumpInfo: boolArg('dump-info'), + noFrequencyBasedMinification: boolArg('no-frequency-based-minification'), ); return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart index 9f1780cd29..80d9bda409 100644 --- a/packages/flutter_tools/lib/src/commands/channel.dart +++ b/packages/flutter_tools/lib/src/commands/channel.dart @@ -39,7 +39,7 @@ class ChannelCommand extends FlutterCommand { switch (rest.length) { case 0: await _listChannels( - showAll: boolArgDeprecated('all'), + showAll: boolArg('all'), verbose: globalResults?['verbose'] == true, ); return FlutterCommandResult.success(); diff --git a/packages/flutter_tools/lib/src/commands/config.dart b/packages/flutter_tools/lib/src/commands/config.dart index 17cb578dac..349490d2b3 100644 --- a/packages/flutter_tools/lib/src/commands/config.dart +++ b/packages/flutter_tools/lib/src/commands/config.dart @@ -111,12 +111,12 @@ class ConfigCommand extends FlutterCommand { ' flutter config --android-studio-dir "/opt/Android Studio"'); } - if (boolArgDeprecated('machine')) { + if (boolArg('machine')) { await handleMachine(); return FlutterCommandResult.success(); } - if (boolArgDeprecated('clear-features')) { + if (boolArg('clear-features')) { for (final Feature feature in allFeatures) { final String? configSetting = feature.configSetting; if (configSetting != null) { @@ -127,7 +127,7 @@ class ConfigCommand extends FlutterCommand { } if (argResults?.wasParsed('analytics') ?? false) { - final bool value = boolArgDeprecated('analytics'); + final bool value = boolArg('analytics'); // The tool sends the analytics event *before* toggling the flag // intentionally to be sure that opt-out events are sent correctly. AnalyticsConfigEvent(enabled: value).send(); @@ -142,11 +142,11 @@ class ConfigCommand extends FlutterCommand { } if (argResults?.wasParsed('android-sdk') ?? false) { - _updateConfig('android-sdk', stringArgDeprecated('android-sdk')!); + _updateConfig('android-sdk', stringArg('android-sdk')!); } if (argResults?.wasParsed('android-studio-dir') ?? false) { - _updateConfig('android-studio-dir', stringArgDeprecated('android-studio-dir')!); + _updateConfig('android-studio-dir', stringArg('android-studio-dir')!); } if (argResults?.wasParsed('clear-ios-signing-cert') ?? false) { @@ -154,7 +154,7 @@ class ConfigCommand extends FlutterCommand { } if (argResults?.wasParsed('build-dir') ?? false) { - final String buildDir = stringArgDeprecated('build-dir')!; + final String buildDir = stringArg('build-dir')!; if (globals.fs.path.isAbsolute(buildDir)) { throwToolExit('build-dir should be a relative path'); } @@ -167,7 +167,7 @@ class ConfigCommand extends FlutterCommand { continue; } if (argResults?.wasParsed(configSetting) ?? false) { - final bool keyValue = boolArgDeprecated(configSetting); + final bool keyValue = boolArg(configSetting); globals.config.setValue(configSetting, keyValue); globals.printStatus('Setting "$configSetting" value to "$keyValue".'); } diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 002592a033..e9914bf15d 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -95,9 +95,9 @@ class CreateCommand extends CreateBase { @override Future get usageValues async { return CustomDimensions( - commandCreateProjectType: stringArgDeprecated('template'), - commandCreateAndroidLanguage: stringArgDeprecated('android-language'), - commandCreateIosLanguage: stringArgDeprecated('ios-language'), + commandCreateProjectType: stringArg('template'), + commandCreateAndroidLanguage: stringArg('android-language'), + commandCreateIosLanguage: stringArg('ios-language'), ); } @@ -207,7 +207,7 @@ class CreateCommand extends CreateBase { validateOutputDirectoryArg(); String? sampleCode; final String? sampleArgument = stringArg('sample'); - final bool emptyArgument = boolArg('empty') ?? false; + final bool emptyArgument = boolArg('empty'); if (sampleArgument != null) { final String? templateArgument = stringArg('template'); if (templateArgument != null && stringToProjectType(templateArgument) != FlutterProjectType.app) { @@ -256,10 +256,10 @@ class CreateCommand extends CreateBase { final String organization = await getOrganization(); - final bool overwrite = boolArgDeprecated('overwrite'); + final bool overwrite = boolArg('overwrite'); validateProjectDir(overwrite: overwrite); - if (boolArgDeprecated('with-driver-test')) { + if (boolArg('with-driver-test')) { globals.printWarning( 'The "--with-driver-test" argument has been deprecated and will no longer add a flutter ' 'driver template. Instead, learn how to use package:integration_test by ' @@ -309,13 +309,13 @@ class CreateCommand extends CreateBase { organization: organization, projectName: projectName, titleCaseProjectName: titleCaseProjectName, - projectDescription: stringArgDeprecated('description'), + projectDescription: stringArg('description'), flutterRoot: flutterRoot, withPlatformChannelPluginHook: generateMethodChannelsPlugin, withFfiPluginHook: generateFfiPlugin, withEmptyMain: emptyArgument, - androidLanguage: stringArgDeprecated('android-language'), - iosLanguage: stringArgDeprecated('ios-language'), + androidLanguage: stringArg('android-language'), + iosLanguage: stringArg('ios-language'), iosDevelopmentTeam: developmentTeam, ios: includeIos, android: includeAndroid, @@ -324,7 +324,7 @@ class CreateCommand extends CreateBase { macos: includeMacos, windows: includeWindows, dartSdkVersionBounds: "'>=$dartSdk <4.0.0'", - implementationTests: boolArgDeprecated('implementation-tests'), + implementationTests: boolArg('implementation-tests'), agpVersion: gradle.templateAndroidGradlePluginVersion, kotlinVersion: gradle.templateKotlinGradlePluginVersion, gradleVersion: gradle.templateDefaultGradleVersion, @@ -408,12 +408,12 @@ class CreateCommand extends CreateBase { break; } - if (boolArgDeprecated('pub')) { + if (boolArg('pub')) { final FlutterProject project = FlutterProject.fromDirectory(relativeDir); await pub.get( context: pubContext, project: project, - offline: boolArgDeprecated('offline'), + offline: boolArg('offline'), outputMode: PubOutputMode.summaryOnly, ); await project.ensureReadyForPlatformSpecificTooling( @@ -505,7 +505,7 @@ Your $application code is in $relativeAppMain. }) async { int generatedCount = 0; final String? description = argResults!.wasParsed('description') - ? stringArgDeprecated('description') + ? stringArg('description') : 'A new Flutter module project.'; templateContext['description'] = description; generatedCount += await renderTemplate( @@ -526,7 +526,7 @@ Your $application code is in $relativeAppMain. }) async { int generatedCount = 0; final String? description = argResults!.wasParsed('description') - ? stringArgDeprecated('description') + ? stringArg('description') : 'A new Flutter package project.'; templateContext['description'] = description; generatedCount += await renderTemplate( @@ -564,7 +564,7 @@ Your $application code is in $relativeAppMain. templateContext['no_platforms'] = !willAddPlatforms; int generatedCount = 0; final String? description = argResults!.wasParsed('description') - ? stringArgDeprecated('description') + ? stringArg('description') : 'A new Flutter plugin project.'; templateContext['description'] = description; generatedCount += await renderMerged( @@ -634,7 +634,7 @@ Your $application code is in $relativeAppMain. templateContext['no_platforms'] = !willAddPlatforms; int generatedCount = 0; final String? description = argResults!.wasParsed('description') - ? stringArgDeprecated('description') + ? stringArg('description') : 'A new Flutter FFI plugin project.'; templateContext['description'] = description; generatedCount += await renderMerged( diff --git a/packages/flutter_tools/lib/src/commands/create_base.dart b/packages/flutter_tools/lib/src/commands/create_base.dart index 8340076f56..cde0e989e7 100644 --- a/packages/flutter_tools/lib/src/commands/create_base.dart +++ b/packages/flutter_tools/lib/src/commands/create_base.dart @@ -253,7 +253,7 @@ abstract class CreateBase extends FlutterCommand { /// If `--org` is not specified, returns the organization from the existing project. @protected Future getOrganization() async { - String? organization = stringArgDeprecated('org'); + String? organization = stringArg('org'); if (!argResults!.wasParsed('org')) { final FlutterProject project = FlutterProject.fromDirectory(projectDir); final Set existingOrganizations = await project.organizationNames; @@ -326,8 +326,8 @@ abstract class CreateBase extends FlutterCommand { @protected String get projectName { final String projectName = - stringArgDeprecated('project-name') ?? globals.fs.path.basename(projectDirPath); - if (!boolArgDeprecated('skip-name-checks')) { + stringArg('project-name') ?? globals.fs.path.basename(projectDirPath); + if (!boolArg('skip-name-checks')) { final String? error = _validateProjectName(projectName); if (error != null) { throwToolExit(error); @@ -527,7 +527,7 @@ abstract class CreateBase extends FlutterCommand { final bool windowsPlatform = templateContext['windows'] as bool? ?? false; final bool webPlatform = templateContext['web'] as bool? ?? false; - if (boolArgDeprecated('pub')) { + if (boolArg('pub')) { final Environment environment = Environment( artifacts: globals.artifacts!, logger: globals.logger, @@ -587,7 +587,7 @@ abstract class CreateBase extends FlutterCommand { platforms: platformsForMigrateConfig, projectDirectory: directory, update: false, - currentRevision: stringArgDeprecated('initial-create-revision') ?? globals.flutterVersion.frameworkRevision, + currentRevision: stringArg('initial-create-revision') ?? globals.flutterVersion.frameworkRevision, createRevision: globals.flutterVersion.frameworkRevision, logger: globals.logger, ); diff --git a/packages/flutter_tools/lib/src/commands/custom_devices.dart b/packages/flutter_tools/lib/src/commands/custom_devices.dart index aec955e803..30d801e832 100644 --- a/packages/flutter_tools/lib/src/commands/custom_devices.dart +++ b/packages/flutter_tools/lib/src/commands/custom_devices.dart @@ -461,8 +461,8 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { /// /// Only check if `--check` is explicitly specified. (Don't check by default) Future runNonInteractively() async { - final String jsonStr = stringArgDeprecated(_kJson)!; - final bool shouldCheck = boolArgDeprecated(_kCheck); + final String jsonStr = stringArg(_kJson)!; + final bool shouldCheck = boolArg(_kCheck); dynamic json; try { @@ -570,7 +570,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { /// Run interactively (with user prompts), the target device should be /// connected to via ssh. Future runInteractivelySsh() async { - final bool shouldCheck = boolArgDeprecated(_kCheck); + final bool shouldCheck = boolArg(_kCheck); // Listen to the keystrokes stream as late as possible, since it's a // single-subscription stream apparently. @@ -781,10 +781,10 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { Future runCommand() async { checkFeatureEnabled(); - if (stringArgDeprecated(_kJson) != null) { + if (stringArg(_kJson) != null) { return runNonInteractively(); } - if (boolArgDeprecated(_kSsh) == true) { + if (boolArg(_kSsh) == true) { return runInteractivelySsh(); } throw UnsupportedError('Unknown run mode'); diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 8716a0e9ae..de4c252e92 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -67,7 +67,7 @@ class DaemonCommand extends FlutterCommand { if (argResults!['listen-on-tcp-port'] != null) { int? port; try { - port = int.parse(stringArgDeprecated('listen-on-tcp-port')!); + port = int.parse(stringArg('listen-on-tcp-port')!); } on FormatException catch (error) { throwToolExit('Invalid port for `--listen-on-tcp-port`: $error'); } diff --git a/packages/flutter_tools/lib/src/commands/debug_adapter.dart b/packages/flutter_tools/lib/src/commands/debug_adapter.dart index 8ebf3f8391..b060897b4b 100644 --- a/packages/flutter_tools/lib/src/commands/debug_adapter.dart +++ b/packages/flutter_tools/lib/src/commands/debug_adapter.dart @@ -58,7 +58,7 @@ class DebugAdapterCommand extends FlutterCommand { platform: globals.platform, ipv6: ipv6 ?? false, enableDds: enableDds, - test: boolArgDeprecated('test'), + test: boolArg('test'), onError: (Object? e) { globals.printError( 'Input could not be parsed as a Debug Adapter Protocol message.\n' diff --git a/packages/flutter_tools/lib/src/commands/devices.dart b/packages/flutter_tools/lib/src/commands/devices.dart index 8d1adf7513..8e392f1cb8 100644 --- a/packages/flutter_tools/lib/src/commands/devices.dart +++ b/packages/flutter_tools/lib/src/commands/devices.dart @@ -36,7 +36,7 @@ class DevicesCommand extends FlutterCommand { @override Duration? get deviceDiscoveryTimeout { if (argResults?['timeout'] != null) { - final int? timeoutSeconds = int.tryParse(stringArgDeprecated('timeout')!); + final int? timeoutSeconds = int.tryParse(stringArg('timeout')!); if (timeoutSeconds == null) { throwToolExit('Could not parse -t/--timeout argument. It must be an integer.'); } @@ -67,7 +67,7 @@ class DevicesCommand extends FlutterCommand { ); await output.findAndOutputAllTargetDevices( - machine: boolArgDeprecated('machine'), + machine: boolArg('machine'), ); return FlutterCommandResult.success(); diff --git a/packages/flutter_tools/lib/src/commands/doctor.dart b/packages/flutter_tools/lib/src/commands/doctor.dart index 67890fbf06..43c1f313ea 100644 --- a/packages/flutter_tools/lib/src/commands/doctor.dart +++ b/packages/flutter_tools/lib/src/commands/doctor.dart @@ -35,7 +35,7 @@ class DoctorCommand extends FlutterCommand { Future runCommand() async { globals.flutterVersion.fetchTagsAndUpdate(); if (argResults?.wasParsed('check-for-remote-artifacts') ?? false) { - final String engineRevision = stringArgDeprecated('check-for-remote-artifacts')!; + final String engineRevision = stringArg('check-for-remote-artifacts')!; if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) { final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false; if (success) { @@ -48,7 +48,7 @@ class DoctorCommand extends FlutterCommand { } } final bool success = await globals.doctor?.diagnose( - androidLicenses: boolArgDeprecated('android-licenses'), + androidLicenses: boolArg('android-licenses'), verbose: verbose, androidLicenseValidator: androidLicenseValidator, ) ?? false; diff --git a/packages/flutter_tools/lib/src/commands/downgrade.dart b/packages/flutter_tools/lib/src/commands/downgrade.dart index 2172ee76f2..8206c8dba6 100644 --- a/packages/flutter_tools/lib/src/commands/downgrade.dart +++ b/packages/flutter_tools/lib/src/commands/downgrade.dart @@ -91,7 +91,7 @@ class DowngradeCommand extends FlutterCommand { _fileSystem ??= globals.fs; String workingDirectory = Cache.flutterRoot!; if (argResults!.wasParsed('working-directory')) { - workingDirectory = stringArgDeprecated('working-directory')!; + workingDirectory = stringArg('working-directory')!; _flutterVersion = FlutterVersion(workingDirectory: workingDirectory); } @@ -127,7 +127,7 @@ class DowngradeCommand extends FlutterCommand { // If there is a terminal attached, prompt the user to confirm the downgrade. final Stdio stdio = _stdio!; final Terminal terminal = _terminal!; - if (stdio.hasTerminal && boolArgDeprecated('prompt')) { + if (stdio.hasTerminal && boolArg('prompt')) { terminal.usesTerminalUi = true; final String result = await terminal.promptForCharInput( const ['y', 'n'], diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 9c1f8a7e9b..bc98d8b457 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -73,7 +73,6 @@ class DriveCommand extends RunCommandBase { addMultidexOption(); argParser ..addFlag('keep-app-running', - defaultsTo: null, help: 'Will keep the Flutter application running when done testing.\n' 'By default, "flutter drive" stops the application after tests are finished, ' 'and "--keep-app-running" overrides this. On the other hand, if "--use-existing-app" ' @@ -171,7 +170,7 @@ class DriveCommand extends RunCommandBase { // specified not to. @override bool get shouldRunPub { - if (argResults!.wasParsed('pub') && !boolArgDeprecated('pub')) { + if (argResults!.wasParsed('pub') && !boolArg('pub')) { return false; } return true; @@ -196,9 +195,9 @@ class DriveCommand extends RunCommandBase { @override final List aliases = ['driver']; - String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser); - String? get screenshot => stringArgDeprecated('screenshot'); + String? get screenshot => stringArg('screenshot'); @override bool get startPausedDefault => true; @@ -206,7 +205,7 @@ class DriveCommand extends RunCommandBase { @override bool get cachePubGet => false; - String? get applicationBinaryPath => stringArgDeprecated(FlutterOptions.kUseApplicationBinary); + String? get applicationBinaryPath => stringArg(FlutterOptions.kUseApplicationBinary); Future get targetedDevice async { return findTargetDevice( @@ -226,7 +225,7 @@ class DriveCommand extends RunCommandBase { _logger.printTrace('Network device is being used. Changing `publish-port` to be enabled.'); return false; } - return !boolArgDeprecated('publish-port'); + return !boolArg('publish-port'); } @override @@ -279,7 +278,7 @@ class DriveCommand extends RunCommandBase { bool screenshotTaken = false; try { - if (stringArgDeprecated('use-existing-app') == null) { + if (stringArg('use-existing-app') == null) { await driverService.start( buildInfo, device, @@ -294,14 +293,14 @@ class DriveCommand extends RunCommandBase { 'trace-startup': traceStartup, if (web) '--no-launch-chrome': true, - if (boolArgDeprecated('multidex')) + if (boolArg('multidex')) 'multidex': true, } ); } else { - final Uri? uri = Uri.tryParse(stringArgDeprecated('use-existing-app')!); + final Uri? uri = Uri.tryParse(stringArg('use-existing-app')!); if (uri == null) { - throwToolExit('Invalid VM Service URI: ${stringArgDeprecated('use-existing-app')}'); + throwToolExit('Invalid VM Service URI: ${stringArg('use-existing-app')}'); } await driverService.reuseApplication( uri, @@ -316,16 +315,16 @@ class DriveCommand extends RunCommandBase { stringsArg('test-arguments'), {}, packageConfig, - chromeBinary: stringArgDeprecated('chrome-binary'), - headless: boolArgDeprecated('headless'), + chromeBinary: stringArg('chrome-binary'), + headless: boolArg('headless'), webBrowserFlags: stringsArg(FlutterOptions.kWebBrowserFlag), - browserDimension: stringArgDeprecated('browser-dimension')!.split(','), - browserName: stringArgDeprecated('browser-name'), - driverPort: stringArgDeprecated('driver-port') != null - ? int.tryParse(stringArgDeprecated('driver-port')!) + browserDimension: stringArg('browser-dimension')!.split(','), + browserName: stringArg('browser-name'), + driverPort: stringArg('driver-port') != null + ? int.tryParse(stringArg('driver-port')!) : null, - androidEmulator: boolArgDeprecated('android-emulator'), - profileMemory: stringArgDeprecated('profile-memory'), + androidEmulator: boolArg('android-emulator'), + profileMemory: stringArg('profile-memory'), ); // If the test is sent a signal or times out, take a screenshot @@ -344,11 +343,11 @@ class DriveCommand extends RunCommandBase { screenshotTaken = true; } - if (boolArgDeprecated('keep-app-running')) { + if (boolArg('keep-app-running')) { _logger.printStatus('Leaving the application running.'); } else { - final File? skslFile = stringArgDeprecated('write-sksl-on-exit') != null - ? _fileSystem.file(stringArgDeprecated('write-sksl-on-exit')) + final File? skslFile = stringArg('write-sksl-on-exit') != null + ? _fileSystem.file(stringArg('write-sksl-on-exit')) : null; await driverService.stop(userIdentifier: userIdentifier, writeSkslOnExit: skslFile); } @@ -422,7 +421,7 @@ class DriveCommand extends RunCommandBase { String? _getTestFile() { if (argResults!['driver'] != null) { - return stringArgDeprecated('driver'); + return stringArg('driver'); } // If the --driver argument wasn't provided, then derive the value from diff --git a/packages/flutter_tools/lib/src/commands/emulators.dart b/packages/flutter_tools/lib/src/commands/emulators.dart index f317f69a16..b991bccba4 100644 --- a/packages/flutter_tools/lib/src/commands/emulators.dart +++ b/packages/flutter_tools/lib/src/commands/emulators.dart @@ -48,9 +48,9 @@ class EmulatorsCommand extends FlutterCommand { final ArgResults argumentResults = argResults!; if (argumentResults.wasParsed('launch')) { final bool coldBoot = argumentResults.wasParsed('cold'); - await _launchEmulator(stringArgDeprecated('launch')!, coldBoot: coldBoot); + await _launchEmulator(stringArg('launch')!, coldBoot: coldBoot); } else if (argumentResults.wasParsed('create')) { - await _createEmulator(name: stringArgDeprecated('name')); + await _createEmulator(name: stringArg('name')); } else { final String? searchText = argumentResults.rest.isNotEmpty diff --git a/packages/flutter_tools/lib/src/commands/generate_localizations.dart b/packages/flutter_tools/lib/src/commands/generate_localizations.dart index 233b69396f..7323aa0f1b 100644 --- a/packages/flutter_tools/lib/src/commands/generate_localizations.dart +++ b/packages/flutter_tools/lib/src/commands/generate_localizations.dart @@ -226,7 +226,7 @@ class GenerateLocalizationsCommand extends FlutterCommand { final List outputFileList; File? untranslatedMessagesFile; - bool format = boolArg('format') ?? false; + bool format = boolArg('format'); if (_fileSystem.file('l10n.yaml').existsSync()) { final LocalizationOptions options = parseLocalizationsOptions( @@ -249,23 +249,23 @@ class GenerateLocalizationsCommand extends FlutterCommand { untranslatedMessagesFile = generator.untranslatedMessagesFile; format = format || options.format; } else { - final String inputPathString = stringArgDeprecated('arb-dir')!; // Has default value, cannot be null. - final String? outputPathString = stringArgDeprecated('output-dir'); - final String outputFileString = stringArgDeprecated('output-localization-file')!; // Has default value, cannot be null. - final String templateArbFileName = stringArgDeprecated('template-arb-file')!; // Has default value, cannot be null. - final String? untranslatedMessagesFilePath = stringArgDeprecated('untranslated-messages-file'); - final String classNameString = stringArgDeprecated('output-class')!; // Has default value, cannot be null. + final String inputPathString = stringArg('arb-dir')!; // Has default value, cannot be null. + final String? outputPathString = stringArg('output-dir'); + final String outputFileString = stringArg('output-localization-file')!; // Has default value, cannot be null. + final String templateArbFileName = stringArg('template-arb-file')!; // Has default value, cannot be null. + final String? untranslatedMessagesFilePath = stringArg('untranslated-messages-file'); + final String classNameString = stringArg('output-class')!; // Has default value, cannot be null. final List preferredSupportedLocales = stringsArg('preferred-supported-locales'); - final String? headerString = stringArgDeprecated('header'); - final String? headerFile = stringArgDeprecated('header-file'); - final bool useDeferredLoading = boolArgDeprecated('use-deferred-loading'); - final String? inputsAndOutputsListPath = stringArgDeprecated('gen-inputs-and-outputs-list'); - final bool useSyntheticPackage = boolArgDeprecated('synthetic-package'); - final String? projectPathString = stringArgDeprecated('project-dir'); - final bool areResourceAttributesRequired = boolArgDeprecated('required-resource-attributes'); - final bool usesNullableGetter = boolArgDeprecated('nullable-getter'); - final bool useEscaping = boolArgDeprecated('use-escaping'); - final bool suppressWarnings = boolArgDeprecated('suppress-warnings'); + final String? headerString = stringArg('header'); + final String? headerFile = stringArg('header-file'); + final bool useDeferredLoading = boolArg('use-deferred-loading'); + final String? inputsAndOutputsListPath = stringArg('gen-inputs-and-outputs-list'); + final bool useSyntheticPackage = boolArg('synthetic-package'); + final String? projectPathString = stringArg('project-dir'); + final bool areResourceAttributesRequired = boolArg('required-resource-attributes'); + final bool usesNullableGetter = boolArg('nullable-getter'); + final bool useEscaping = boolArg('use-escaping'); + final bool suppressWarnings = boolArg('suppress-warnings'); precacheLanguageAndRegionTags(); diff --git a/packages/flutter_tools/lib/src/commands/ide_config.dart b/packages/flutter_tools/lib/src/commands/ide_config.dart index 1597d289c5..25fd2f213d 100644 --- a/packages/flutter_tools/lib/src/commands/ide_config.dart +++ b/packages/flutter_tools/lib/src/commands/ide_config.dart @@ -153,7 +153,7 @@ class IdeConfigCommand extends FlutterCommand { manifest.add('$relativePath${Template.copyTemplateExtension}'); continue; } - if (boolArgDeprecated('overwrite')) { + if (boolArg('overwrite')) { finalDestinationFile.deleteSync(); globals.printStatus(' $relativeDestination (overwritten)'); } else { @@ -174,7 +174,7 @@ class IdeConfigCommand extends FlutterCommand { } // If we're not overwriting, then we're not going to remove missing items either. - if (!boolArgDeprecated('overwrite')) { + if (!boolArg('overwrite')) { return; } @@ -213,7 +213,7 @@ class IdeConfigCommand extends FlutterCommand { throwToolExit('Currently, the only supported IDE is IntelliJ\n$usage', exitCode: 2); } - if (boolArgDeprecated('update-templates')) { + if (boolArg('update-templates')) { _handleTemplateUpdate(); return FlutterCommandResult.success(); } @@ -231,7 +231,7 @@ class IdeConfigCommand extends FlutterCommand { globals.printStatus('Updating IDE configuration for Flutter tree at $dirPath...'); int generatedCount = 0; generatedCount += _renderTemplate(_ideName, dirPath, { - 'withRootModule': boolArgDeprecated('with-root-module'), + 'withRootModule': boolArg('with-root-module'), 'android': true, }); @@ -254,7 +254,7 @@ class IdeConfigCommand extends FlutterCommand { return template.render( globals.fs.directory(dirPath), context, - overwriteExisting: boolArgDeprecated('overwrite'), + overwriteExisting: boolArg('overwrite'), ); } } diff --git a/packages/flutter_tools/lib/src/commands/install.dart b/packages/flutter_tools/lib/src/commands/install.dart index f2a72cc5ac..feb2741e42 100644 --- a/packages/flutter_tools/lib/src/commands/install.dart +++ b/packages/flutter_tools/lib/src/commands/install.dart @@ -37,10 +37,10 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts Device? device; - bool get uninstallOnly => boolArgDeprecated('uninstall-only'); - String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + bool get uninstallOnly => boolArg('uninstall-only'); + String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser); - String? get _applicationBinaryPath => stringArgDeprecated(FlutterOptions.kUseApplicationBinary); + String? get _applicationBinaryPath => stringArg(FlutterOptions.kUseApplicationBinary); File? get _applicationBinary => _applicationBinaryPath == null ? null : globals.fs.file(_applicationBinaryPath); @override diff --git a/packages/flutter_tools/lib/src/commands/logs.dart b/packages/flutter_tools/lib/src/commands/logs.dart index 1acce6388c..64d100c7bc 100644 --- a/packages/flutter_tools/lib/src/commands/logs.dart +++ b/packages/flutter_tools/lib/src/commands/logs.dart @@ -46,7 +46,7 @@ class LogsCommand extends FlutterCommand { @override Future runCommand() async { final Device cachedDevice = device!; - if (boolArgDeprecated('clear')) { + if (boolArg('clear')) { cachedDevice.clearLogs(); } diff --git a/packages/flutter_tools/lib/src/commands/precache.dart b/packages/flutter_tools/lib/src/commands/precache.dart index 35e664c9b6..f0a2d16d3a 100644 --- a/packages/flutter_tools/lib/src/commands/precache.dart +++ b/packages/flutter_tools/lib/src/commands/precache.dart @@ -102,7 +102,7 @@ class PrecacheCommand extends FlutterCommand { Set _explicitArtifactSelections() { final Map umbrellaForArtifact = _umbrellaForArtifactMap(); final Set selections = {}; - bool explicitlySelected(String name) => boolArgDeprecated(name) && argResults!.wasParsed(name); + bool explicitlySelected(String name) => boolArg(name) && argResults!.wasParsed(name); for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) { final String? umbrellaName = umbrellaForArtifact[artifact.name]; if (explicitlySelected(artifact.name) || @@ -135,15 +135,15 @@ class PrecacheCommand extends FlutterCommand { if (_platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') { await _cache.lock(); } - if (boolArgDeprecated('force')) { + if (boolArg('force')) { _cache.clearStampFiles(); } - final bool includeAllPlatforms = boolArgDeprecated('all-platforms'); + final bool includeAllPlatforms = boolArg('all-platforms'); if (includeAllPlatforms) { _cache.includeAllPlatforms = true; } - if (boolArgDeprecated('use-unsigned-mac-binaries')) { + if (boolArg('use-unsigned-mac-binaries')) { _cache.useUnsignedMacBinaries = true; } final Set explicitlyEnabled = _explicitArtifactSelections(); @@ -160,7 +160,7 @@ class PrecacheCommand extends FlutterCommand { } final String argumentName = umbrellaForArtifact[artifact.name] ?? artifact.name; - if (includeAllPlatforms || boolArgDeprecated(argumentName) || downloadDefaultArtifacts) { + if (includeAllPlatforms || boolArg(argumentName) || downloadDefaultArtifacts) { requiredArtifacts.add(artifact); } } diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 2fd7a88bd9..e57e57395f 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -186,18 +186,18 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment addEnableEmbedderApiFlag(verboseHelp: verboseHelp); } - bool get traceStartup => boolArgDeprecated('trace-startup'); - bool get enableDartProfiling => boolArgDeprecated('enable-dart-profiling'); - bool get cacheSkSL => boolArgDeprecated('cache-sksl'); - bool get dumpSkpOnShaderCompilation => boolArgDeprecated('dump-skp-on-shader-compilation'); - bool get purgePersistentCache => boolArgDeprecated('purge-persistent-cache'); - bool get disableServiceAuthCodes => boolArgDeprecated('disable-service-auth-codes'); - bool get cacheStartupProfile => boolArgDeprecated('cache-startup-profile'); + bool get traceStartup => boolArg('trace-startup'); + bool get enableDartProfiling => boolArg('enable-dart-profiling'); + bool get cacheSkSL => boolArg('cache-sksl'); + bool get dumpSkpOnShaderCompilation => boolArg('dump-skp-on-shader-compilation'); + bool get purgePersistentCache => boolArg('purge-persistent-cache'); + bool get disableServiceAuthCodes => boolArg('disable-service-auth-codes'); + bool get cacheStartupProfile => boolArg('cache-startup-profile'); bool get runningWithPrebuiltApplication => argResults![FlutterOptions.kUseApplicationBinary] != null; - bool get trackWidgetCreation => boolArgDeprecated('track-widget-creation'); - bool get enableImpeller => boolArgDeprecated('enable-impeller'); - bool get uninstallFirst => boolArgDeprecated('uninstall-first'); - bool get enableEmbedderApi => boolArgDeprecated('enable-embedder-api'); + bool get trackWidgetCreation => boolArg('track-widget-creation'); + bool get enableImpeller => boolArg('enable-impeller'); + bool get uninstallFirst => boolArg('uninstall-first'); + bool get enableEmbedderApi => boolArg('enable-embedder-api'); @override bool get reportNullSafety => true; @@ -205,9 +205,9 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment /// Whether to start the application paused by default. bool get startPausedDefault; - String? get route => stringArgDeprecated('route'); + String? get route => stringArg('route'); - String? get traceAllowlist => stringArgDeprecated('trace-allowlist'); + String? get traceAllowlist => stringArg('trace-allowlist'); /// Create a debugging options instance for the current `run` or `drive` invocation. @visibleForTesting @@ -215,7 +215,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment Future createDebuggingOptions(bool webMode) async { final BuildInfo buildInfo = await getBuildInfo(); final int? webBrowserDebugPort = featureFlags.isWebEnabled && argResults!.wasParsed('web-browser-debug-port') - ? int.parse(stringArgDeprecated('web-browser-debug-port')!) + ? int.parse(stringArg('web-browser-debug-port')!) : null; final List webBrowserFlags = featureFlags.isWebEnabled ? stringsArg(FlutterOptions.kWebBrowserFlag) @@ -224,13 +224,13 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment return DebuggingOptions.disabled( buildInfo, dartEntrypointArgs: stringsArg('dart-entrypoint-args'), - hostname: featureFlags.isWebEnabled ? stringArgDeprecated('web-hostname') : '', - port: featureFlags.isWebEnabled ? stringArgDeprecated('web-port') : '', - webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-protocol') == 'sse', - webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-backend-protocol') == 'sse', - webUseSseForInjectedClient: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-injected-client-protocol') == 'sse', - webEnableExposeUrl: featureFlags.isWebEnabled && boolArgDeprecated('web-allow-expose-url'), - webRunHeadless: featureFlags.isWebEnabled && boolArgDeprecated('web-run-headless'), + hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '', + port: featureFlags.isWebEnabled ? stringArg('web-port') : '', + webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse', + webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse', + webUseSseForInjectedClient: featureFlags.isWebEnabled && stringArg('web-server-debug-injected-client-protocol') == 'sse', + webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'), + webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'), webBrowserDebugPort: webBrowserDebugPort, webBrowserFlags: webBrowserFlags, enableImpeller: enableImpeller, @@ -241,20 +241,20 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment } else { return DebuggingOptions.enabled( buildInfo, - startPaused: boolArgDeprecated('start-paused'), - disableServiceAuthCodes: boolArgDeprecated('disable-service-auth-codes'), + startPaused: boolArg('start-paused'), + disableServiceAuthCodes: boolArg('disable-service-auth-codes'), cacheStartupProfile: cacheStartupProfile, enableDds: enableDds, dartEntrypointArgs: stringsArg('dart-entrypoint-args'), - dartFlags: stringArgDeprecated('dart-flags') ?? '', - useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArgDeprecated('use-test-fonts'), - enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArgDeprecated('enable-software-rendering'), - skiaDeterministicRendering: argParser.options.containsKey('skia-deterministic-rendering') && boolArgDeprecated('skia-deterministic-rendering'), - traceSkia: boolArgDeprecated('trace-skia'), + dartFlags: stringArg('dart-flags') ?? '', + useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArg('use-test-fonts'), + enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArg('enable-software-rendering'), + skiaDeterministicRendering: argParser.options.containsKey('skia-deterministic-rendering') && boolArg('skia-deterministic-rendering'), + traceSkia: boolArg('trace-skia'), traceAllowlist: traceAllowlist, - traceSkiaAllowlist: stringArgDeprecated('trace-skia-allowlist'), - traceSystrace: boolArgDeprecated('trace-systrace'), - endlessTraceBuffer: boolArgDeprecated('endless-trace-buffer'), + traceSkiaAllowlist: stringArg('trace-skia-allowlist'), + traceSystrace: boolArg('trace-systrace'), + endlessTraceBuffer: boolArg('endless-trace-buffer'), dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation, cacheSkSL: cacheSkSL, purgePersistentCache: purgePersistentCache, @@ -263,27 +263,27 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment disablePortPublication: await disablePortPublication, ddsPort: ddsPort, devToolsServerAddress: devToolsServerAddress, - verboseSystemLogs: boolArgDeprecated('verbose-system-logs'), - hostname: featureFlags.isWebEnabled ? stringArgDeprecated('web-hostname') : '', - port: featureFlags.isWebEnabled ? stringArgDeprecated('web-port') : '', - webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-protocol') == 'sse', - webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-backend-protocol') == 'sse', - webUseSseForInjectedClient: featureFlags.isWebEnabled && stringArgDeprecated('web-server-debug-injected-client-protocol') == 'sse', - webEnableExposeUrl: featureFlags.isWebEnabled && boolArgDeprecated('web-allow-expose-url'), - webRunHeadless: featureFlags.isWebEnabled && boolArgDeprecated('web-run-headless'), + verboseSystemLogs: boolArg('verbose-system-logs'), + hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '', + port: featureFlags.isWebEnabled ? stringArg('web-port') : '', + webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse', + webUseSseForDebugBackend: featureFlags.isWebEnabled && stringArg('web-server-debug-backend-protocol') == 'sse', + webUseSseForInjectedClient: featureFlags.isWebEnabled && stringArg('web-server-debug-injected-client-protocol') == 'sse', + webEnableExposeUrl: featureFlags.isWebEnabled && boolArg('web-allow-expose-url'), + webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'), webBrowserDebugPort: webBrowserDebugPort, webBrowserFlags: webBrowserFlags, - webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArgDeprecated('web-enable-expression-evaluation'), - webLaunchUrl: featureFlags.isWebEnabled ? stringArgDeprecated('web-launch-url') : null, - vmserviceOutFile: stringArgDeprecated('vmservice-out-file'), + webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArg('web-enable-expression-evaluation'), + webLaunchUrl: featureFlags.isWebEnabled ? stringArg('web-launch-url') : null, + vmserviceOutFile: stringArg('vmservice-out-file'), fastStart: argParser.options.containsKey('fast-start') - && boolArgDeprecated('fast-start') + && boolArg('fast-start') && !runningWithPrebuiltApplication, - nullAssertions: boolArgDeprecated('null-assertions'), - nativeNullAssertions: boolArgDeprecated('native-null-assertions'), + nullAssertions: boolArg('null-assertions'), + nativeNullAssertions: boolArg('native-null-assertions'), enableImpeller: enableImpeller, uninstallFirst: uninstallFirst, - serveObservatory: boolArgDeprecated('serve-observatory'), + serveObservatory: boolArg('serve-observatory'), enableDartProfiling: enableDartProfiling, enableEmbedderApi: enableEmbedderApi, ); @@ -379,7 +379,7 @@ class RunCommand extends RunCommandBase { final String name = 'run'; @override - DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : _deviceDeprecationBehavior; + DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : _deviceDeprecationBehavior; DeprecationBehavior _deviceDeprecationBehavior = DeprecationBehavior.none; @override @@ -391,7 +391,7 @@ class RunCommand extends RunCommandBase { List? devices; bool webMode = false; - String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser); @override bool get startPausedDefault => false; @@ -500,13 +500,13 @@ class RunCommand extends RunCommandBase { } bool shouldUseHotMode(BuildInfo buildInfo) { - final bool hotArg = boolArgDeprecated('hot'); + final bool hotArg = boolArg('hot'); final bool shouldUseHotMode = hotArg && !traceStartup; return buildInfo.isDebug && shouldUseHotMode; } - bool get stayResident => boolArgDeprecated('resident'); - bool get awaitFirstFrameWhenTracing => boolArgDeprecated('await-first-frame-when-tracing'); + bool get stayResident => boolArg('resident'); + bool get awaitFirstFrameWhenTracing => boolArg('await-first-frame-when-tracing'); @override Future validateCommand() async { @@ -553,15 +553,15 @@ class RunCommand extends RunCommandBase { flutterDevices, target: targetFile, debuggingOptions: await createDebuggingOptions(webMode), - benchmarkMode: boolArgDeprecated('benchmark'), + benchmarkMode: boolArg('benchmark'), applicationBinary: applicationBinaryPath == null ? null : globals.fs.file(applicationBinaryPath), - projectRootPath: stringArgDeprecated('project-root'), - dillOutputPath: stringArgDeprecated('output-dill'), + projectRootPath: stringArg('project-root'), + dillOutputPath: stringArg('output-dill'), stayResident: stayResident, ipv6: ipv6 ?? false, - multidexEnabled: boolArgDeprecated('multidex'), + multidexEnabled: boolArg('multidex'), ); } else if (webMode) { return webRunnerFactory!.createWebRunner( @@ -588,7 +588,7 @@ class RunCommand extends RunCommandBase { : globals.fs.file(applicationBinaryPath), ipv6: ipv6 ?? false, stayResident: stayResident, - multidexEnabled: boolArgDeprecated('multidex'), + multidexEnabled: boolArg('multidex'), ); } @@ -613,9 +613,9 @@ class RunCommand extends RunCommandBase { // debug mode. final BuildInfo buildInfo = await getBuildInfo(); final bool hotMode = shouldUseHotMode(buildInfo); - final String? applicationBinaryPath = stringArgDeprecated(FlutterOptions.kUseApplicationBinary); + final String? applicationBinaryPath = stringArg(FlutterOptions.kUseApplicationBinary); - if (boolArgDeprecated('machine')) { + if (boolArg('machine')) { if (devices!.length > 1) { throwToolExit('"--machine" does not support "-d all".'); } @@ -629,13 +629,13 @@ class RunCommand extends RunCommandBase { ? null : globals.fs.file(applicationBinaryPath), trackWidgetCreation: trackWidgetCreation, - projectRootPath: stringArgDeprecated('project-root'), + projectRootPath: stringArg('project-root'), packagesFilePath: globalResults!['packages'] as String?, - dillOutputPath: stringArgDeprecated('output-dill'), + dillOutputPath: stringArg('output-dill'), ipv6: ipv6 ?? false, - multidexEnabled: boolArgDeprecated('multidex'), + multidexEnabled: boolArg('multidex'), userIdentifier: userIdentifier, - enableDevTools: boolArgDeprecated(FlutterCommand.kEnableDevTools), + enableDevTools: boolArg(FlutterCommand.kEnableDevTools), ); } on Exception catch (error) { throwToolExit(error.toString()); @@ -667,7 +667,7 @@ class RunCommand extends RunCommandBase { } } if (await device.isLocalEmulator && await device.supportsHardwareRendering) { - if (boolArgDeprecated('enable-software-rendering')) { + if (boolArg('enable-software-rendering')) { globals.printStatus( 'Using software rendering with device ${device.name}. You may get better performance ' 'with hardware mode by configuring hardware rendering for your device.' @@ -725,8 +725,8 @@ class RunCommand extends RunCommandBase { terminal: globals.terminal, signals: globals.signals, processInfo: globals.processInfo, - reportReady: boolArgDeprecated('report-ready'), - pidFile: stringArgDeprecated('pid-file'), + reportReady: boolArg('report-ready'), + pidFile: stringArg('pid-file'), ) ..registerSignalHandlers() ..setupTerminal(); @@ -736,7 +736,7 @@ class RunCommand extends RunCommandBase { try { final int? result = await runner.run( appStartedCompleter: appStartedTimeRecorder, - enableDevTools: stayResident && boolArgDeprecated(FlutterCommand.kEnableDevTools), + enableDevTools: stayResident && boolArg(FlutterCommand.kEnableDevTools), route: route, ); handler?.stop(); diff --git a/packages/flutter_tools/lib/src/commands/screenshot.dart b/packages/flutter_tools/lib/src/commands/screenshot.dart index c291acb723..c97e385b69 100644 --- a/packages/flutter_tools/lib/src/commands/screenshot.dart +++ b/packages/flutter_tools/lib/src/commands/screenshot.dart @@ -96,7 +96,7 @@ class ScreenshotCommand extends FlutterCommand { @override Future verifyThenRunCommand(String? commandPath) async { - await _validateOptions(stringArgDeprecated(_kType), stringArgDeprecated(_kVmServiceUrl)); + await _validateOptions(stringArg(_kType), stringArg(_kVmServiceUrl)); return super.verifyThenRunCommand(commandPath); } @@ -104,11 +104,11 @@ class ScreenshotCommand extends FlutterCommand { Future runCommand() async { File? outputFile; if (argResults?.wasParsed(_kOut) ?? false) { - outputFile = fs.file(stringArgDeprecated(_kOut)); + outputFile = fs.file(stringArg(_kOut)); } bool success = true; - switch (stringArgDeprecated(_kType)) { + switch (stringArg(_kType)) { case _kDeviceType: await runScreenshot(outputFile); break; @@ -150,7 +150,7 @@ class ScreenshotCommand extends FlutterCommand { } Future runSkia(File? outputFile) async { - final Uri vmServiceUrl = Uri.parse(stringArgDeprecated(_kVmServiceUrl)!); + final Uri vmServiceUrl = Uri.parse(stringArg(_kVmServiceUrl)!); final FlutterVmService vmService = await connectToVmService(vmServiceUrl, logger: globals.logger); final vm_service.Response? skp = await vmService.screenshotSkp(); if (skp == null) { @@ -174,7 +174,7 @@ class ScreenshotCommand extends FlutterCommand { } Future runRasterizer(File? outputFile) async { - final Uri vmServiceUrl = Uri.parse(stringArgDeprecated(_kVmServiceUrl)!); + final Uri vmServiceUrl = Uri.parse(stringArg(_kVmServiceUrl)!); final FlutterVmService vmService = await connectToVmService(vmServiceUrl, logger: globals.logger); final vm_service.Response? response = await vmService.screenshot(); if (response == null) { diff --git a/packages/flutter_tools/lib/src/commands/shell_completion.dart b/packages/flutter_tools/lib/src/commands/shell_completion.dart index 43dca0b104..5fe8de3013 100644 --- a/packages/flutter_tools/lib/src/commands/shell_completion.dart +++ b/packages/flutter_tools/lib/src/commands/shell_completion.dart @@ -54,7 +54,7 @@ class ShellCompletionCommand extends FlutterCommand { } final File outputFile = globals.fs.file(rest.first); - if (outputFile.existsSync() && !boolArgDeprecated('overwrite')) { + if (outputFile.existsSync() && !boolArg('overwrite')) { throwToolExit( 'Output file ${outputFile.path} already exists, will not overwrite. ' 'Use --overwrite to force overwriting existing output file.', diff --git a/packages/flutter_tools/lib/src/commands/symbolize.dart b/packages/flutter_tools/lib/src/commands/symbolize.dart index d8393f15d9..061d375236 100644 --- a/packages/flutter_tools/lib/src/commands/symbolize.dart +++ b/packages/flutter_tools/lib/src/commands/symbolize.dart @@ -68,14 +68,14 @@ class SymbolizeCommand extends FlutterCommand { if (argResults?.wasParsed('debug-info') != true) { throwToolExit('"--debug-info" is required to symbolize stack traces.'); } - final String debugInfoPath = stringArgDeprecated('debug-info')!; + final String debugInfoPath = stringArg('debug-info')!; if (debugInfoPath.endsWith('.dSYM') ? !_fileSystem.isDirectorySync(debugInfoPath) : !_fileSystem.isFileSync(debugInfoPath)) { throwToolExit('$debugInfoPath does not exist.'); } - if ((argResults?.wasParsed('input') ?? false) && !_fileSystem.isFileSync(stringArgDeprecated('input')!)) { - throwToolExit('${stringArgDeprecated('input')} does not exist.'); + if ((argResults?.wasParsed('input') ?? false) && !_fileSystem.isFileSync(stringArg('input')!)) { + throwToolExit('${stringArg('input')} does not exist.'); } return super.validateCommand(); } @@ -87,7 +87,7 @@ class SymbolizeCommand extends FlutterCommand { // Configure output to either specified file or stdout. if (argResults?.wasParsed('output') ?? false) { - final File outputFile = _fileSystem.file(stringArgDeprecated('output')); + final File outputFile = _fileSystem.file(stringArg('output')); if (!outputFile.parent.existsSync()) { outputFile.parent.createSync(recursive: true); } @@ -103,12 +103,12 @@ class SymbolizeCommand extends FlutterCommand { // Configure input from either specified file or stdin. if (argResults?.wasParsed('input') ?? false) { - input = _fileSystem.file(stringArgDeprecated('input')).openRead(); + input = _fileSystem.file(stringArg('input')).openRead(); } else { input = _stdio.stdin; } - String debugInfoPath = stringArgDeprecated('debug-info')!; + String debugInfoPath = stringArg('debug-info')!; // If it's a dSYM container, expand the path to the actual DWARF. if (debugInfoPath.endsWith('.dSYM')) { diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 801856b76a..fbd85c346f 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -244,7 +244,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { // Use [DeviceBasedDevelopmentArtifacts]. ? await super.requiredArtifacts : {}; - if (stringArgDeprecated('platform') == 'chrome') { + if (stringArg('platform') == 'chrome') { results.add(DevelopmentArtifact.web); } return results; @@ -313,11 +313,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { 'directory (or one of its subdirectories).'); } final FlutterProject flutterProject = FlutterProject.current(); - final bool buildTestAssets = boolArgDeprecated('test-assets'); + final bool buildTestAssets = boolArg('test-assets'); final List names = stringsArg('name'); final List plainNames = stringsArg('plain-name'); - final String? tags = stringArgDeprecated('tags'); - final String? excludeTags = stringArgDeprecated('exclude-tags'); + final String? tags = stringArg('tags'); + final String? excludeTags = stringArg('exclude-tags'); final BuildInfo buildInfo = await getBuildInfo(forcedBuildMode: BuildMode.debug); TestTimeRecorder? testTimeRecorder; @@ -343,7 +343,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { join(flutterProject.directory.path, 'build', 'unit_test_assets'); } - final bool startPaused = boolArgDeprecated('start-paused'); + final bool startPaused = boolArg('start-paused'); if (startPaused && _testFileUris.length != 1) { throwToolExit( 'When using --start-paused, you must specify a single test file to run.', @@ -351,7 +351,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ); } - int? jobs = int.tryParse(stringArgDeprecated('concurrency')!); + int? jobs = int.tryParse(stringArg('concurrency')!); if (jobs == null || jobs <= 0 || !jobs.isFinite) { throwToolExit( 'Could not parse -j/--concurrency argument. It must be an integer greater than zero.' @@ -369,13 +369,13 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { jobs = 1; } - final int? shardIndex = int.tryParse(stringArgDeprecated('shard-index') ?? ''); + final int? shardIndex = int.tryParse(stringArg('shard-index') ?? ''); if (shardIndex != null && (shardIndex < 0 || !shardIndex.isFinite)) { throwToolExit( 'Could not parse --shard-index=$shardIndex argument. It must be an integer greater than -1.'); } - final int? totalShards = int.tryParse(stringArgDeprecated('total-shards') ?? ''); + final int? totalShards = int.tryParse(stringArg('total-shards') ?? ''); if (totalShards != null && (totalShards <= 0 || !totalShards.isFinite)) { throwToolExit( 'Could not parse --total-shards=$totalShards argument. It must be an integer greater than zero.'); @@ -390,10 +390,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { 'If you set --shard-index you need to also set --total-shards.'); } - final bool machine = boolArgDeprecated('machine'); + final bool machine = boolArg('machine'); CoverageCollector? collector; - if (boolArgDeprecated('coverage') || boolArgDeprecated('merge-coverage') || - boolArgDeprecated('branch-coverage')) { + if (boolArg('coverage') || boolArg('merge-coverage') || + boolArg('branch-coverage')) { final String projectName = flutterProject.manifest.appName; collector = CoverageCollector( verbose: !machine, @@ -401,7 +401,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { packagesPath: buildInfo.packagesPath, resolver: await CoverageCollector.getResolver(buildInfo.packagesPath), testTimeRecorder: testTimeRecorder, - branchCoverage: boolArgDeprecated('branch-coverage'), + branchCoverage: boolArg('branch-coverage'), ); } @@ -415,12 +415,12 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { final DebuggingOptions debuggingOptions = DebuggingOptions.enabled( buildInfo, startPaused: startPaused, - disableServiceAuthCodes: boolArgDeprecated('disable-service-auth-codes'), - serveObservatory: boolArgDeprecated('serve-observatory'), + disableServiceAuthCodes: boolArg('disable-service-auth-codes'), + serveObservatory: boolArg('serve-observatory'), // On iOS >=14, keeping this enabled will leave a prompt on the screen. disablePortPublication: true, enableDds: enableDds, - nullAssertions: boolArgDeprecated(FlutterOptions.kNullAssertions), + nullAssertions: boolArg(FlutterOptions.kNullAssertions), ); Device? integrationTestDevice; @@ -464,23 +464,23 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { tags: tags, excludeTags: excludeTags, watcher: watcher, - enableVmService: collector != null || startPaused || boolArgDeprecated('enable-vmservice'), - ipv6: boolArgDeprecated('ipv6'), + enableVmService: collector != null || startPaused || boolArg('enable-vmservice'), + ipv6: boolArg('ipv6'), machine: machine, - updateGoldens: boolArgDeprecated('update-goldens'), + updateGoldens: boolArg('update-goldens'), concurrency: jobs, testAssetDirectory: testAssetDirectory, flutterProject: flutterProject, - web: stringArgDeprecated('platform') == 'chrome', - randomSeed: stringArgDeprecated('test-randomize-ordering-seed'), - reporter: stringArgDeprecated('reporter'), + web: stringArg('platform') == 'chrome', + randomSeed: stringArg('test-randomize-ordering-seed'), + reporter: stringArg('reporter'), fileReporter: stringArg('file-reporter'), - timeout: stringArgDeprecated('timeout'), - runSkipped: boolArgDeprecated('run-skipped'), + timeout: stringArg('timeout'), + runSkipped: boolArg('run-skipped'), shardIndex: shardIndex, totalShards: totalShards, integrationTestDevice: integrationTestDevice, - integrationTestUserIdentifier: stringArgDeprecated(FlutterOptions.kDeviceUser), + integrationTestUserIdentifier: stringArg(FlutterOptions.kDeviceUser), testTimeRecorder: testTimeRecorder, ); testTimeRecorder?.stop(TestTimePhases.TestRunner, testRunnerTimeRecorderStopwatch!); @@ -488,8 +488,8 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { if (collector != null) { final Stopwatch? collectTimeRecorderStopwatch = testTimeRecorder?.start(TestTimePhases.CoverageDataCollect); final bool collectionResult = await collector.collectCoverageData( - stringArgDeprecated('coverage-path'), - mergeCoverageData: boolArgDeprecated('merge-coverage'), + stringArg('coverage-path'), + mergeCoverageData: boolArg('merge-coverage'), ); testTimeRecorder?.stop(TestTimePhases.CoverageDataCollect, collectTimeRecorderStopwatch!); if (!collectionResult) { diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart index 3110c0b74b..69e2b2e18e 100644 --- a/packages/flutter_tools/lib/src/commands/update_packages.dart +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -179,15 +179,15 @@ class UpdatePackagesCommand extends FlutterCommand { Future runCommand() async { final List packages = runner!.getRepoPackages(); - final bool forceUpgrade = boolArgDeprecated('force-upgrade'); - final bool isPrintPaths = boolArgDeprecated('paths'); - final bool isPrintTransitiveClosure = boolArgDeprecated('transitive-closure'); - final bool isVerifyOnly = boolArgDeprecated('verify-only'); - final bool isConsumerOnly = boolArgDeprecated('consumer-only'); - final bool offline = boolArgDeprecated('offline'); + final bool forceUpgrade = boolArg('force-upgrade'); + final bool isPrintPaths = boolArg('paths'); + final bool isPrintTransitiveClosure = boolArg('transitive-closure'); + final bool isVerifyOnly = boolArg('verify-only'); + final bool isConsumerOnly = boolArg('consumer-only'); + final bool offline = boolArg('offline'); final bool doUpgrade = forceUpgrade || isPrintPaths || isPrintTransitiveClosure; - if (boolArgDeprecated('crash')) { + if (boolArg('crash')) { throw StateError('test crash please ignore.'); } @@ -442,7 +442,7 @@ class UpdatePackagesCommand extends FlutterCommand { context: PubContext.updatePackages, project: FlutterProject.fromDirectory(syntheticPackageDir), upgrade: doUpgrade, - offline: boolArgDeprecated('offline'), + offline: boolArg('offline'), flutterRootOverride: temporaryFlutterSdk?.path, outputMode: PubOutputMode.none, ); @@ -484,15 +484,15 @@ class UpdatePackagesCommand extends FlutterCommand { } } - if (boolArgDeprecated('transitive-closure')) { + if (boolArg('transitive-closure')) { tree._dependencyTree.forEach((String from, Set to) { globals.printStatus('$from -> $to'); }); return true; } - if (boolArgDeprecated('paths')) { - showDependencyPaths(from: stringArgDeprecated('from')!, to: stringArgDeprecated('to')!, tree: tree); + if (boolArg('paths')) { + showDependencyPaths(from: stringArg('from')!, to: stringArg('to')!, tree: tree); return true; } @@ -526,7 +526,7 @@ class UpdatePackagesCommand extends FlutterCommand { ); try { // int.tryParse will not accept null, but will convert empty string to null - final int? maxJobs = int.tryParse(stringArgDeprecated('jobs') ?? ''); + final int? maxJobs = int.tryParse(stringArg('jobs') ?? ''); final TaskQueue queue = TaskQueue(maxJobs: maxJobs); for (final Directory dir in packages) { unawaited(queue.add(() async { diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 158597cac9..294eb33899 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -71,16 +71,16 @@ class UpgradeCommand extends FlutterCommand { @override Future runCommand() { - _commandRunner.workingDirectory = stringArgDeprecated('working-directory') ?? Cache.flutterRoot!; + _commandRunner.workingDirectory = stringArg('working-directory') ?? Cache.flutterRoot!; return _commandRunner.runCommand( - force: boolArgDeprecated('force'), - continueFlow: boolArgDeprecated('continue'), - testFlow: stringArgDeprecated('working-directory') != null, + force: boolArg('force'), + continueFlow: boolArg('continue'), + testFlow: stringArg('working-directory') != null, gitTagVersion: GitTagVersion.determine(globals.processUtils, globals.platform), - flutterVersion: stringArgDeprecated('working-directory') == null + flutterVersion: stringArg('working-directory') == null ? globals.flutterVersion : FlutterVersion(workingDirectory: _commandRunner.workingDirectory), - verifyOnly: boolArgDeprecated('verify-only'), + verifyOnly: boolArg('verify-only'), ); } } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index ef8bb46485..306779de7d 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -203,7 +203,7 @@ abstract class FlutterCommand extends Command { DeprecationBehavior get deprecationBehavior => DeprecationBehavior.none; - bool get shouldRunPub => _usesPubOption && boolArgDeprecated('pub'); + bool get shouldRunPub => _usesPubOption && boolArg('pub'); bool get shouldUpdateCache => true; @@ -320,7 +320,7 @@ abstract class FlutterCommand extends Command { String get targetFile { if (argResults?.wasParsed('target') ?? false) { - return stringArgDeprecated('target')!; + return stringArg('target')!; } final List? rest = argResults?.rest; if (rest != null && rest.isNotEmpty) { @@ -339,7 +339,7 @@ abstract class FlutterCommand extends Command { /// This can be overridden by some of its subclasses. String? get fileSystemScheme => argParser.options.containsKey(FlutterOptions.kFileSystemScheme) - ? stringArgDeprecated(FlutterOptions.kFileSystemScheme) + ? stringArg(FlutterOptions.kFileSystemScheme) : null; /// The values of the `--filesystem-root` argument. @@ -485,7 +485,7 @@ abstract class FlutterCommand extends Command { throwToolExit( 'The "--[no-]dds" and "--[no-]disable-dds" arguments are mutually exclusive. Only specify "--[no-]dds".'); } - ddsEnabled = !boolArgDeprecated('disable-dds'); + ddsEnabled = !boolArg('disable-dds'); // TODO(ianh): enable the following code once google3 is migrated away from --disable-dds (and add test to flutter_command_test.dart) if (false) { // ignore: dead_code if (ddsEnabled) { @@ -497,7 +497,7 @@ abstract class FlutterCommand extends Command { } } } else { - ddsEnabled = boolArgDeprecated('dds'); + ddsEnabled = boolArg('dds'); } return ddsEnabled; }(); @@ -507,9 +507,9 @@ abstract class FlutterCommand extends Command { || (argResults?.wasParsed('host-vmservice-port') ?? false); int _tryParseHostVmservicePort() { - final String? vmServicePort = stringArgDeprecated(vmServicePortOption) ?? - stringArgDeprecated(observatoryPortOption); - final String? hostPort = stringArgDeprecated('host-vmservice-port'); + final String? vmServicePort = stringArg(vmServicePortOption) ?? + stringArg(observatoryPortOption); + final String? hostPort = stringArg('host-vmservice-port'); if (vmServicePort == null && hostPort == null) { throwToolExit('Invalid port for `--vm-service-port/--host-vmservice-port`'); } @@ -526,7 +526,7 @@ abstract class FlutterCommand extends Command { return _tryParseHostVmservicePort(); } else if (argResults?.wasParsed('dds-port') ?? false) { // If an explicit DDS port is provided, use dds-port for DDS. - return int.tryParse(stringArgDeprecated('dds-port')!) ?? 0; + return int.tryParse(stringArg('dds-port')!) ?? 0; } // Otherwise, DDS can bind to a random port. return 0; @@ -534,7 +534,7 @@ abstract class FlutterCommand extends Command { Uri? get devToolsServerAddress { if (argResults?.wasParsed(kDevToolsServerAddress) ?? false) { - final Uri? uri = Uri.tryParse(stringArgDeprecated(kDevToolsServerAddress)!); + final Uri? uri = Uri.tryParse(stringArg(kDevToolsServerAddress)!); if (uri != null && uri.host.isNotEmpty && uri.port != 0) { return uri; } @@ -572,7 +572,7 @@ abstract class FlutterCommand extends Command { /// /// If no port is set, returns null. int? get deviceVmservicePort { - final String? devicePort = stringArgDeprecated('device-vmservice-port'); + final String? devicePort = stringArg('device-vmservice-port'); if (!_usesPortOption || devicePort == null) { return null; } @@ -592,7 +592,7 @@ abstract class FlutterCommand extends Command { ); } - Future get disablePortPublication async => !boolArgDeprecated('publish-port'); + Future get disablePortPublication async => !boolArg('publish-port'); void usesIpv6Flag({required bool verboseHelp}) { argParser.addFlag(ipv6Flag, @@ -605,7 +605,7 @@ abstract class FlutterCommand extends Command { _usesIpv6Flag = true; } - bool? get ipv6 => _usesIpv6Flag ? boolArgDeprecated('ipv6') : null; + bool? get ipv6 => _usesIpv6Flag ? boolArg('ipv6') : null; void usesBuildNumberOption() { argParser.addOption('build-number', @@ -701,7 +701,7 @@ abstract class FlutterCommand extends Command { late final Duration? deviceDiscoveryTimeout = () { if ((argResults?.options.contains(FlutterOptions.kDeviceTimeout) ?? false) && (argResults?.wasParsed(FlutterOptions.kDeviceTimeout) ?? false)) { - final int? timeoutSeconds = int.tryParse(stringArgDeprecated(FlutterOptions.kDeviceTimeout)!); + final int? timeoutSeconds = int.tryParse(stringArg(FlutterOptions.kDeviceTimeout)!); if (timeoutSeconds == null) { throwToolExit( 'Could not parse "--${FlutterOptions.kDeviceTimeout}" argument. It must be an integer.'); } @@ -975,13 +975,13 @@ abstract class FlutterCommand extends Command { BuildMode getBuildMode() { // No debug when _excludeDebug is true. // If debug is not excluded, then take the command line flag. - final bool debugResult = !_excludeDebug && boolArgDeprecated('debug'); - final bool jitReleaseResult = !_excludeRelease && boolArgDeprecated('jit-release'); - final bool releaseResult = !_excludeRelease && boolArgDeprecated('release'); + final bool debugResult = !_excludeDebug && boolArg('debug'); + final bool jitReleaseResult = !_excludeRelease && boolArg('jit-release'); + final bool releaseResult = !_excludeRelease && boolArg('release'); final List modeFlags = [ debugResult, jitReleaseResult, - boolArgDeprecated('profile'), + boolArg('profile'), releaseResult, ]; if (modeFlags.where((bool flag) => flag).length > 1) { @@ -991,7 +991,7 @@ abstract class FlutterCommand extends Command { if (debugResult) { return BuildMode.debug; } - if (boolArgDeprecated('profile')) { + if (boolArg('profile')) { return BuildMode.profile; } if (releaseResult) { @@ -1066,10 +1066,10 @@ abstract class FlutterCommand extends Command { /// each other. Future getBuildInfo({ BuildMode? forcedBuildMode, File? forcedTargetFile }) async { final bool trackWidgetCreation = argParser.options.containsKey('track-widget-creation') && - boolArgDeprecated('track-widget-creation'); + boolArg('track-widget-creation'); final String? buildNumber = argParser.options.containsKey('build-number') - ? stringArgDeprecated('build-number') + ? stringArg('build-number') : null; final File packagesFile = globals.fs.file( @@ -1099,13 +1099,13 @@ abstract class FlutterCommand extends Command { } String? codeSizeDirectory; - if (argParser.options.containsKey(FlutterOptions.kAnalyzeSize) && boolArgDeprecated(FlutterOptions.kAnalyzeSize)) { + if (argParser.options.containsKey(FlutterOptions.kAnalyzeSize) && boolArg(FlutterOptions.kAnalyzeSize)) { Directory directory = globals.fsUtils.getUniqueDirectory( globals.fs.directory(getBuildDirectory()), 'flutter_size', ); - if (argParser.options.containsKey(FlutterOptions.kCodeSizeDirectory) && stringArgDeprecated(FlutterOptions.kCodeSizeDirectory) != null) { - directory = globals.fs.directory(stringArgDeprecated(FlutterOptions.kCodeSizeDirectory)); + if (argParser.options.containsKey(FlutterOptions.kCodeSizeDirectory) && stringArg(FlutterOptions.kCodeSizeDirectory) != null) { + directory = globals.fs.directory(stringArg(FlutterOptions.kCodeSizeDirectory)); } directory.createSync(recursive: true); codeSizeDirectory = directory.path; @@ -1140,7 +1140,7 @@ abstract class FlutterCommand extends Command { // This mode is only used for commands which do not build a single target like // 'flutter test'. nullSafetyMode = NullSafetyMode.autodetect; - } else if (boolArgDeprecated(FlutterOptions.kNullSafety)) { + } else if (boolArg(FlutterOptions.kNullSafety)) { nullSafetyMode = NullSafetyMode.sound; extraFrontEndOptions.add('--sound-null-safety'); } else { @@ -1150,14 +1150,14 @@ abstract class FlutterCommand extends Command { } final bool dartObfuscation = argParser.options.containsKey(FlutterOptions.kDartObfuscationOption) - && boolArgDeprecated(FlutterOptions.kDartObfuscationOption); + && boolArg(FlutterOptions.kDartObfuscationOption); final String? splitDebugInfoPath = argParser.options.containsKey(FlutterOptions.kSplitDebugInfoOption) - ? stringArgDeprecated(FlutterOptions.kSplitDebugInfoOption) + ? stringArg(FlutterOptions.kSplitDebugInfoOption) : null; final bool androidGradleDaemon = !argParser.options.containsKey(FlutterOptions.kAndroidGradleDaemon) - || boolArgDeprecated(FlutterOptions.kAndroidGradleDaemon); + || boolArg(FlutterOptions.kAndroidGradleDaemon); final List androidProjectArgs = argParser.options.containsKey(FlutterOptions.kAndroidProjectArgs) ? stringsArg(FlutterOptions.kAndroidProjectArgs) @@ -1179,10 +1179,10 @@ abstract class FlutterCommand extends Command { final bool treeShakeIcons = argParser.options.containsKey('tree-shake-icons') && buildMode.isPrecompiled == true - && boolArgDeprecated('tree-shake-icons'); + && boolArg('tree-shake-icons'); final String? bundleSkSLPath = argParser.options.containsKey(FlutterOptions.kBundleSkSLPathOption) - ? stringArgDeprecated(FlutterOptions.kBundleSkSLPathOption) + ? stringArg(FlutterOptions.kBundleSkSLPathOption) : null; if (bundleSkSLPath != null && !globals.fs.isFileSync(bundleSkSLPath)) { @@ -1190,7 +1190,7 @@ abstract class FlutterCommand extends Command { } final String? performanceMeasurementFile = argParser.options.containsKey(FlutterOptions.kPerformanceMeasurementFile) - ? stringArgDeprecated(FlutterOptions.kPerformanceMeasurementFile) + ? stringArg(FlutterOptions.kPerformanceMeasurementFile) : null; final Map? defineConfigJsonMap = extractDartDefineConfigJsonMap(); @@ -1198,7 +1198,7 @@ abstract class FlutterCommand extends Command { WebRendererMode webRenderer = WebRendererMode.autoDetect; if (argParser.options.containsKey(FlutterOptions.kWebRendererFlag)) { - final WebRendererMode? mappedMode = _webRendererModeMap[stringArgDeprecated(FlutterOptions.kWebRendererFlag)!]; + final WebRendererMode? mappedMode = _webRendererModeMap[stringArg(FlutterOptions.kWebRendererFlag)!]; if (mappedMode != null) { webRenderer = mappedMode; } @@ -1207,7 +1207,7 @@ abstract class FlutterCommand extends Command { return BuildInfo(buildMode, argParser.options.containsKey('flavor') - ? stringArgDeprecated('flavor') + ? stringArg('flavor') : null, trackWidgetCreation: trackWidgetCreation, extraFrontEndOptions: extraFrontEndOptions.isNotEmpty @@ -1220,7 +1220,7 @@ abstract class FlutterCommand extends Command { fileSystemScheme: fileSystemScheme, buildNumber: buildNumber, buildName: argParser.options.containsKey('build-name') - ? stringArgDeprecated('build-name') + ? stringArg('build-name') : null, treeShakeIcons: treeShakeIcons, splitDebugInfoPath: splitDebugInfoPath, @@ -1238,10 +1238,10 @@ abstract class FlutterCommand extends Command { packageConfig: packageConfig, androidProjectArgs: androidProjectArgs, initializeFromDill: argParser.options.containsKey(FlutterOptions.kInitializeFromDill) - ? stringArgDeprecated(FlutterOptions.kInitializeFromDill) + ? stringArg(FlutterOptions.kInitializeFromDill) : null, assumeInitializeFromDillUpToDate: argParser.options.containsKey(FlutterOptions.kAssumeInitializeFromDillUpToDate) - && boolArgDeprecated(FlutterOptions.kAssumeInitializeFromDillUpToDate), + && boolArg(FlutterOptions.kAssumeInitializeFromDillUpToDate), ); } @@ -1280,7 +1280,7 @@ abstract class FlutterCommand extends Command { overrides: {FlutterCommand: () => this}, body: () async { if (_usesFatalWarnings) { - globals.logger.fatalWarnings = boolArgDeprecated(FlutterOptions.kFatalWarnings); + globals.logger.fatalWarnings = boolArg(FlutterOptions.kFatalWarnings); } // Prints the welcome message if needed. globals.flutterUsage.printWelcome(); @@ -1451,7 +1451,7 @@ abstract class FlutterCommand extends Command { // ios-deploy on macOS) are required to determine `requiredArtifacts`. final bool offline; if (argParser.options.containsKey('offline')) { - offline = boolArgDeprecated('offline'); + offline = boolArg('offline'); } else { offline = false; } @@ -1615,27 +1615,17 @@ abstract class FlutterCommand extends Command { ApplicationPackageFactory? applicationPackages; - /// Gets the parsed command-line option named [name] as a `bool`. - /// This has been deprecated, use [boolArg] instead. - bool boolArgDeprecated(String name) => argResults?[name] as bool? ?? false; - - /// Gets the parsed command-line option named [name] as a `bool?`. - bool? boolArg(String name) { - if (!argParser.options.containsKey(name)) { - return null; - } - return argResults![name] as bool; - } + /// Gets the parsed command-line flag named [name] as a `bool`. + /// + /// If no flag named [name] was added to the [ArgParser], an [ArgumentError] + /// will be thrown. + bool boolArg(String name) => argResults![name] as bool; /// Gets the parsed command-line option named [name] as a `String`. - String? stringArgDeprecated(String name) => argResults?[name] as String?; - - String? stringArg(String name) { - if (!argParser.options.containsKey(name)) { - return null; - } - return argResults![name] as String?; - } + /// + /// If no option named [name] was added to the [ArgParser], an [ArgumentError] + /// will be thrown. + String? stringArg(String name) => argResults![name] as String?; /// Gets the parsed command-line option named [name] as `List`. List stringsArg(String name) { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart index 4aa6cfcf46..c177293af0 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; +import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/android/android_device.dart'; @@ -673,6 +674,23 @@ void main() { FakeDevice(targetPlatform: TargetPlatform.android_arm, platformType: PlatformType.android), ]; final TestRunCommandForUsageValues command = TestRunCommandForUsageValues(devices: devices); + final CommandRunner runner = createTestCommandRunner(command); + try { + // run the command so that CLI args are parsed + await runner.run(['run']); + } on ToolExit catch (error) { + // we can ignore the ToolExit, as we are only interested in + // command.usageValues. + expect( + error, + isA().having( + (ToolExit exception) => exception.message, + 'message', + contains('No pubspec.yaml file found'), + ), + ); + } + final CustomDimensions dimensions = await command.usageValues; expect(dimensions, const CustomDimensions( @@ -696,6 +714,23 @@ void main() { FakeIOSDevice(interfaceType: IOSDeviceConnectionInterface.usb, sdkNameAndVersion: 'iOS 16.2'), ]; final TestRunCommandForUsageValues command = TestRunCommandForUsageValues(devices: devices); + final CommandRunner runner = createTestCommandRunner(command); + try { + // run the command so that CLI args are parsed + await runner.run(['run']); + } on ToolExit catch (error) { + // we can ignore the ToolExit, as we are only interested in + // command.usageValues. + expect( + error, + isA().having( + (ToolExit exception) => exception.message, + 'message', + contains('No pubspec.yaml file found'), + ), + ); + } + final CustomDimensions dimensions = await command.usageValues; expect(dimensions, const CustomDimensions( @@ -720,6 +755,23 @@ void main() { FakeIOSDevice(interfaceType: IOSDeviceConnectionInterface.network, sdkNameAndVersion: 'iOS 16.2'), ]; final TestRunCommandForUsageValues command = TestRunCommandForUsageValues(devices: devices); + final CommandRunner runner = createTestCommandRunner(command); + try { + // run the command so that CLI args are parsed + await runner.run(['run']); + } on ToolExit catch (error) { + // we can ignore the ToolExit, as we are only interested in + // command.usageValues. + expect( + error, + isA().having( + (ToolExit exception) => exception.message, + 'message', + contains('No pubspec.yaml file found'), + ), + ); + } + final CustomDimensions dimensions = await command.usageValues; expect(dimensions, const CustomDimensions( @@ -745,6 +797,22 @@ void main() { FakeIOSDevice(interfaceType: IOSDeviceConnectionInterface.usb, sdkNameAndVersion: 'iOS 16.2'), ]; final TestRunCommandForUsageValues command = TestRunCommandForUsageValues(devices: devices); + final CommandRunner runner = createTestCommandRunner(command); + try { + // run the command so that CLI args are parsed + await runner.run(['run']); + } on ToolExit catch (error) { + // we can ignore the ToolExit, as we are only interested in + // command.usageValues. + expect( + error, + isA().having( + (ToolExit exception) => exception.message, + 'message', + contains('No pubspec.yaml file found'), + ), + ); + } final CustomDimensions dimensions = await command.usageValues; expect(dimensions, const CustomDimensions( diff --git a/packages/flutter_tools/test/general.shard/args_test.dart b/packages/flutter_tools/test/general.shard/args_test.dart index 4f638211fa..7c1fb1fd2a 100644 --- a/packages/flutter_tools/test/general.shard/args_test.dart +++ b/packages/flutter_tools/test/general.shard/args_test.dart @@ -47,13 +47,13 @@ void main() { await runner.run(['dummy', '--key']); expect(command.boolArg('key'), true); - expect(command.boolArg('empty'), null); + expect(() => command.boolArg('non-existent'), throwsArgumentError); - expect(command.boolArgDeprecated('key'), true); - expect(() => command.boolArgDeprecated('empty'), throwsA(const TypeMatcher())); + expect(command.boolArg('key'), true); + expect(() => command.boolArg('non-existent'), throwsA(const TypeMatcher())); expect(command.boolArg('key-false'), false); - expect(command.boolArgDeprecated('key-false'), false); + expect(command.boolArg('key-false'), false); }); testUsingContext('String? safe argResults', () async { @@ -72,10 +72,10 @@ void main() { await runner.run(['dummy', '--key=value']); expect(command.stringArg('key'), 'value'); - expect(command.stringArg('empty'), null); + expect(() => command.stringArg('non-existent'), throwsArgumentError); - expect(command.stringArgDeprecated('key'), 'value'); - expect(() => command.stringArgDeprecated('empty'), throwsA(const TypeMatcher())); + expect(command.stringArg('key'), 'value'); + expect(() => command.stringArg('non-existent'), throwsA(const TypeMatcher())); }); testUsingContext('List safe argResults', () async { @@ -97,7 +97,7 @@ void main() { await runner.run(['dummy', '--key', 'a']); // throws error when trying to parse non-existent key. - expect(() => command.stringsArg('empty'),throwsA(const TypeMatcher())); + expect(() => command.stringsArg('non-existent'), throwsA(const TypeMatcher())); expect(command.stringsArg('key'), ['a']);