[flutter_tools] stringArg refactor (#103231)
This commit is contained in:
@@ -293,7 +293,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|
||||
String get targetFile {
|
||||
if (argResults?.wasParsed('target') ?? false) {
|
||||
return stringArg('target')!;
|
||||
return stringArgDeprecated('target')!;
|
||||
}
|
||||
final List<String>? rest = argResults?.rest;
|
||||
if (rest != null && rest.isNotEmpty) {
|
||||
@@ -312,7 +312,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
/// This can be overridden by some of its subclasses.
|
||||
String? get fileSystemScheme =>
|
||||
argParser.options.containsKey(FlutterOptions.kFileSystemScheme)
|
||||
? stringArg(FlutterOptions.kFileSystemScheme)
|
||||
? stringArgDeprecated(FlutterOptions.kFileSystemScheme)
|
||||
: null;
|
||||
|
||||
/// The values of the `--filesystem-root` argument.
|
||||
@@ -450,8 +450,8 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|| (argResults?.wasParsed('host-vmservice-port') ?? false);
|
||||
|
||||
int _tryParseHostVmservicePort() {
|
||||
final String? observatoryPort = stringArg('observatory-port');
|
||||
final String? hostPort = stringArg('host-vmservice-port');
|
||||
final String? observatoryPort = stringArgDeprecated('observatory-port');
|
||||
final String? hostPort = stringArgDeprecated('host-vmservice-port');
|
||||
if (observatoryPort == null && hostPort == null) {
|
||||
throwToolExit('Invalid port for `--observatory-port/--host-vmservice-port`');
|
||||
}
|
||||
@@ -468,7 +468,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
return _tryParseHostVmservicePort();
|
||||
} else if (argResults?.wasParsed('dds-port') ?? false) {
|
||||
// If an explicit DDS port is provided, use dds-port for DDS.
|
||||
return int.tryParse(stringArg('dds-port')!) ?? 0;
|
||||
return int.tryParse(stringArgDeprecated('dds-port')!) ?? 0;
|
||||
}
|
||||
// Otherwise, DDS can bind to a random port.
|
||||
return 0;
|
||||
@@ -476,7 +476,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|
||||
Uri? get devToolsServerAddress {
|
||||
if (argResults?.wasParsed(kDevToolsServerAddress) ?? false) {
|
||||
final Uri? uri = Uri.tryParse(stringArg(kDevToolsServerAddress)!);
|
||||
final Uri? uri = Uri.tryParse(stringArgDeprecated(kDevToolsServerAddress)!);
|
||||
if (uri != null && uri.host.isNotEmpty && uri.port != 0) {
|
||||
return uri;
|
||||
}
|
||||
@@ -513,7 +513,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
///
|
||||
/// If no port is set, returns null.
|
||||
int? get deviceVmservicePort {
|
||||
final String? devicePort = stringArg('device-vmservice-port');
|
||||
final String? devicePort = stringArgDeprecated('device-vmservice-port');
|
||||
if (!_usesPortOption || devicePort == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -626,7 +626,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
late final Duration? deviceDiscoveryTimeout = () {
|
||||
if ((argResults?.options.contains(FlutterOptions.kDeviceTimeout) ?? false)
|
||||
&& (argResults?.wasParsed(FlutterOptions.kDeviceTimeout) ?? false)) {
|
||||
final int? timeoutSeconds = int.tryParse(stringArg(FlutterOptions.kDeviceTimeout)!);
|
||||
final int? timeoutSeconds = int.tryParse(stringArgDeprecated(FlutterOptions.kDeviceTimeout)!);
|
||||
if (timeoutSeconds == null) {
|
||||
throwToolExit( 'Could not parse "--${FlutterOptions.kDeviceTimeout}" argument. It must be an integer.');
|
||||
}
|
||||
@@ -980,7 +980,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
boolArg('track-widget-creation');
|
||||
|
||||
final String? buildNumber = argParser.options.containsKey('build-number')
|
||||
? stringArg('build-number')
|
||||
? stringArgDeprecated('build-number')
|
||||
: null;
|
||||
|
||||
final File packagesFile = globals.fs.file(
|
||||
@@ -1015,8 +1015,8 @@ abstract class FlutterCommand extends Command<void> {
|
||||
globals.fs.directory(getBuildDirectory()),
|
||||
'flutter_size',
|
||||
);
|
||||
if (argParser.options.containsKey(FlutterOptions.kCodeSizeDirectory) && stringArg(FlutterOptions.kCodeSizeDirectory) != null) {
|
||||
directory = globals.fs.directory(stringArg(FlutterOptions.kCodeSizeDirectory));
|
||||
if (argParser.options.containsKey(FlutterOptions.kCodeSizeDirectory) && stringArgDeprecated(FlutterOptions.kCodeSizeDirectory) != null) {
|
||||
directory = globals.fs.directory(stringArgDeprecated(FlutterOptions.kCodeSizeDirectory));
|
||||
}
|
||||
directory.createSync(recursive: true);
|
||||
codeSizeDirectory = directory.path;
|
||||
@@ -1059,7 +1059,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
&& boolArg(FlutterOptions.kDartObfuscationOption);
|
||||
|
||||
final String? splitDebugInfoPath = argParser.options.containsKey(FlutterOptions.kSplitDebugInfoOption)
|
||||
? stringArg(FlutterOptions.kSplitDebugInfoOption)
|
||||
? stringArgDeprecated(FlutterOptions.kSplitDebugInfoOption)
|
||||
: null;
|
||||
|
||||
final bool androidGradleDaemon = !argParser.options.containsKey(FlutterOptions.kAndroidGradleDaemon)
|
||||
@@ -1088,7 +1088,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
&& boolArg('tree-shake-icons');
|
||||
|
||||
final String? bundleSkSLPath = argParser.options.containsKey(FlutterOptions.kBundleSkSLPathOption)
|
||||
? stringArg(FlutterOptions.kBundleSkSLPathOption)
|
||||
? stringArgDeprecated(FlutterOptions.kBundleSkSLPathOption)
|
||||
: null;
|
||||
|
||||
if (bundleSkSLPath != null && !globals.fs.isFileSync(bundleSkSLPath)) {
|
||||
@@ -1096,7 +1096,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
}
|
||||
|
||||
final String? performanceMeasurementFile = argParser.options.containsKey(FlutterOptions.kPerformanceMeasurementFile)
|
||||
? stringArg(FlutterOptions.kPerformanceMeasurementFile)
|
||||
? stringArgDeprecated(FlutterOptions.kPerformanceMeasurementFile)
|
||||
: null;
|
||||
|
||||
List<String> dartDefines = argParser.options.containsKey(FlutterOptions.kDartDefinesOption)
|
||||
@@ -1104,12 +1104,12 @@ abstract class FlutterCommand extends Command<void> {
|
||||
: <String>[];
|
||||
|
||||
if (argParser.options.containsKey('web-renderer')) {
|
||||
dartDefines = updateDartDefines(dartDefines, stringArg('web-renderer')!);
|
||||
dartDefines = updateDartDefines(dartDefines, stringArgDeprecated('web-renderer')!);
|
||||
}
|
||||
|
||||
return BuildInfo(buildMode,
|
||||
argParser.options.containsKey('flavor')
|
||||
? stringArg('flavor')
|
||||
? stringArgDeprecated('flavor')
|
||||
: null,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions.isNotEmpty
|
||||
@@ -1122,7 +1122,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
buildNumber: buildNumber,
|
||||
buildName: argParser.options.containsKey('build-name')
|
||||
? stringArg('build-name')
|
||||
? stringArgDeprecated('build-name')
|
||||
: null,
|
||||
treeShakeIcons: treeShakeIcons,
|
||||
splitDebugInfoPath: splitDebugInfoPath,
|
||||
@@ -1138,7 +1138,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
packageConfig: packageConfig,
|
||||
androidProjectArgs: androidProjectArgs,
|
||||
initializeFromDill: argParser.options.containsKey(FlutterOptions.kInitializeFromDill)
|
||||
? stringArg(FlutterOptions.kInitializeFromDill)
|
||||
? stringArgDeprecated(FlutterOptions.kInitializeFromDill)
|
||||
: null,
|
||||
assumeInitializeFromDillUpToDate: argParser.options.containsKey(FlutterOptions.kAssumeInitializeFromDillUpToDate)
|
||||
&& boolArg(FlutterOptions.kAssumeInitializeFromDillUpToDate),
|
||||
@@ -1522,7 +1522,14 @@ abstract class FlutterCommand extends Command<void> {
|
||||
bool boolArg(String name) => argResults?[name] as bool? ?? false;
|
||||
|
||||
/// Gets the parsed command-line option named [name] as a `String`.
|
||||
String? stringArg(String name) => argResults?[name] as String?;
|
||||
String? stringArgDeprecated(String name) => argResults?[name] as String?;
|
||||
|
||||
String? stringArg(String name) {
|
||||
if (argResults == null || !argParser.options.containsKey(name)) {
|
||||
return null;
|
||||
}
|
||||
return argResults?[name] as String?;
|
||||
}
|
||||
|
||||
/// Gets the parsed command-line option named [name] as an `int`.
|
||||
int? intArg(String name) => argResults?[name] as int?;
|
||||
|
||||
Reference in New Issue
Block a user