diff --git a/packages/flutter_tools/lib/src/base/user_messages.dart b/packages/flutter_tools/lib/src/base/user_messages.dart index bfcead6200..2248d11210 100644 --- a/packages/flutter_tools/lib/src/base/user_messages.dart +++ b/packages/flutter_tools/lib/src/base/user_messages.dart @@ -185,4 +185,97 @@ class UserMessages { String vsCodeVersion(String version) => 'version $version'; String vsCodeLocation(String location) => 'VS Code at $location'; String vsCodeFlutterExtensionMissing(String url) => 'Flutter extension not installed; install from\n$url'; + + // Messages used in FlutterCommand + String flutterElapsedTime(String name, String elapsedTime) => '"flutter $name" took $elapsedTime.'; + String get flutterNoDevelopmentDevice => + "Unable to locate a development device; please run 'flutter doctor' " + 'for information about installing additional components.'; + String flutterNoMatchingDevice(String deviceId) => 'No devices found with name or id ' + "matching '$deviceId'"; + String get flutterNoDevicesFound => 'No devices found'; + String get flutterNoSupportedDevices => 'No supported devices connected.'; + String flutterFoundSpecifiedDevices(int count, String deviceId) => + 'Found $count devices with name or id matching $deviceId:'; + String get flutterSpecifyDeviceWithAllOption => + 'More than one device connected; please specify a device with ' + "the '-d ' flag, or use '-d all' to act on all devices."; + String get flutterSpecifyDevice => + 'More than one device connected; please specify a device with ' + "the '-d ' flag."; + String get flutterNoConnectedDevices => 'No connected devices.'; + String get flutterNoPubspec => + 'Error: No pubspec.yaml file found.\n' + 'This command should be run from the root of your Flutter project.\n' + 'Do not run this command from the root of your git clone of Flutter.'; + String get flutterMergeYamlFiles => + 'Please merge your flutter.yaml into your pubspec.yaml.\n\n' + 'We have changed from having separate flutter.yaml and pubspec.yaml\n' + 'files to having just one pubspec.yaml file. Transitioning is simple:\n' + 'add a line that just says "flutter:" to your pubspec.yaml file, and\n' + 'move everything from your current flutter.yaml file into the\n' + 'pubspec.yaml file, below that line, with everything indented by two\n' + 'extra spaces compared to how it was in the flutter.yaml file. Then, if\n' + 'you had a "name:" line, move that to the top of your "pubspec.yaml"\n' + 'file (you may already have one there), so that there is only one\n' + '"name:" line. Finally, delete the flutter.yaml file.\n\n' + 'For an example of what a new-style pubspec.yaml file might look like,\n' + 'check out the Flutter Gallery pubspec.yaml:\n' + 'https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/pubspec.yaml\n'; + String flutterTargetFileMissing(String path) => 'Target file "$path" not found.'; + String get flutterBasePatchFlagsExclusive => 'Error: Only one of --baseline, --patch is allowed.'; + String get flutterBaselineRequiresDynamic => 'Error: --baseline is allowed only when --dynamic is specified.'; + String get flutterBaselineRequiresTraceFile => 'Error: --baseline requires --compilation-trace-file to be specified.'; + String get flutterPatchRequiresDynamic => 'Error: --patch is allowed only when --dynamic is specified.'; + String get flutterPatchRequiresTraceFile => 'Error: --patch requires --compilation-trace-file to be specified.'; + + // Messages used in FlutterCommandRunner + String runnerNoRoot(String error) => 'Unable to locate flutter root: $error'; + String runnerWrapColumnInvalid(dynamic value) => + 'Argument to --wrap-column must be a positive integer. You supplied $value.'; + String runnerWrapColumnParseError(dynamic value) => + 'Unable to parse argument --wrap-column=$value. Must be a positive integer.'; + String runnerBugReportFinished(String zipFileName) => + 'Bug report written to $zipFileName.\n' + 'Warning: this bug report contains local paths, device identifiers, and log snippets.'; + String get runnerNoRecordTo => 'record-to location not specified'; + String get runnerNoReplayFrom => 'replay-from location not specified'; + String runnerNoEngineBuildDir(String enginePackageName, String engineEnvVar) => + 'Unable to detect local Flutter engine build directory.\n' + 'Either specify a dependency_override for the $enginePackageName package in your pubspec.yaml and ' + 'ensure --package-root is set if necessary, or set the \$$engineEnvVar environment variable, or ' + 'use --local-engine-src-path to specify the path to the root of your flutter/engine repository.'; + String runnerNoEngineBuildDirInPath(String engineSourcePath) => + 'Unable to detect a Flutter engine build directory in $engineSourcePath.\n' + 'Please ensure that $engineSourcePath is a Flutter engine \'src\' directory and that ' + 'you have compiled the engine in that directory, which should produce an \'out\' directory'; + String get runnerLocalEngineRequired => + 'You must specify --local-engine if you are using a locally built engine.'; + String runnerNoEngineBuild(String engineBuildPath) => + 'No Flutter engine build found at $engineBuildPath.'; + String runnerWrongFlutterInstance(String flutterRoot, String currentDir) => + 'Warning: the \'flutter\' tool you are currently running is not the one from the current directory:\n' + ' running Flutter : $flutterRoot\n' + ' current directory: $currentDir\n' + 'This can happen when you have multiple copies of flutter installed. Please check your system path to verify ' + 'that you\'re running the expected version (run \'flutter --version\' to see which flutter is on your path).\n'; + String runnerRemovedFlutterRepo(String flutterRoot, String flutterPath) => + 'Warning! This package referenced a Flutter repository via the .packages file that is ' + 'no longer available. The repository from which the \'flutter\' tool is currently ' + 'executing will be used instead.\n' + ' running Flutter tool: $flutterRoot\n' + ' previous reference : $flutterPath\n' + 'This can happen if you deleted or moved your copy of the Flutter repository, or ' + 'if it was on a volume that is no longer mounted or has been mounted at a ' + 'different location. Please check your system path to verify that you are running ' + 'the expected version (run \'flutter --version\' to see which flutter is on your path).\n'; + String runnerChangedFlutterRepo(String flutterRoot, String flutterPath) => + 'Warning! The \'flutter\' tool you are currently running is from a different Flutter ' + 'repository than the one last used by this package. The repository from which the ' + '\'flutter\' tool is currently executing will be used instead.\n' + ' running Flutter tool: $flutterRoot\n' + ' previous reference : $flutterPath\n' + 'This can happen when you have multiple copies of flutter installed. Please check ' + 'your system path to verify that you are running the expected version (run ' + '\'flutter --version\' to see which flutter is on your path).\n'; } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index e63159fde5..a43d3007c8 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -14,6 +14,7 @@ import '../base/common.dart'; import '../base/context.dart'; import '../base/file_system.dart'; import '../base/time.dart'; +import '../base/user_messages.dart'; import '../base/utils.dart'; import '../build_info.dart'; import '../bundle.dart' as bundle; @@ -475,7 +476,7 @@ abstract class FlutterCommand extends Command { rethrow; } finally { final DateTime endTime = systemClock.now(); - printTrace('"flutter $name" took ${getElapsedAsMilliseconds(endTime.difference(startTime))}.'); + printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime)))); // This is checking the result of the call to 'usagePath' // (a Future), and not the result of evaluating the Future. if (usagePath != null) { @@ -549,19 +550,17 @@ abstract class FlutterCommand extends Command { /// then print an error message and return null. Future> findAllTargetDevices() async { if (!doctor.canLaunchAnything) { - printError("Unable to locate a development device; please run 'flutter doctor' " - 'for information about installing additional components.'); + printError(userMessages.flutterNoDevelopmentDevice); return null; } List devices = await deviceManager.getDevices().toList(); if (devices.isEmpty && deviceManager.hasSpecifiedDeviceId) { - printStatus('No devices found with name or id ' - "matching '${deviceManager.specifiedDeviceId}'"); + printStatus(userMessages.flutterNoMatchingDevice(deviceManager.specifiedDeviceId)); return null; } else if (devices.isEmpty && deviceManager.hasSpecifiedAllDevices) { - printStatus('No devices found'); + printStatus(userMessages.flutterNoDevicesFound); return null; } else if (devices.isEmpty) { printNoConnectedDevices(); @@ -571,15 +570,13 @@ abstract class FlutterCommand extends Command { devices = devices.where((Device device) => device.isSupported()).toList(); if (devices.isEmpty) { - printStatus('No supported devices connected.'); + printStatus(userMessages.flutterNoSupportedDevices); return null; } else if (devices.length > 1 && !deviceManager.hasSpecifiedAllDevices) { if (deviceManager.hasSpecifiedDeviceId) { - printStatus('Found ${devices.length} devices with name or id matching ' - "'${deviceManager.specifiedDeviceId}':"); + printStatus(userMessages.flutterFoundSpecifiedDevices(devices.length, deviceManager.specifiedDeviceId)); } else { - printStatus('More than one device connected; please specify a device with ' - "the '-d ' flag, or use '-d all' to act on all devices."); + printStatus(userMessages.flutterSpecifyDeviceWithAllOption); devices = await deviceManager.getAllConnectedDevices().toList(); } printStatus(''); @@ -598,8 +595,7 @@ abstract class FlutterCommand extends Command { if (deviceList == null) return null; if (deviceList.length > 1) { - printStatus('More than one device connected; please specify a device with ' - "the '-d ' flag."); + printStatus(userMessages.flutterSpecifyDevice); deviceList = await deviceManager.getAllConnectedDevices().toList(); printStatus(''); await Device.printDevices(deviceList); @@ -609,7 +605,7 @@ abstract class FlutterCommand extends Command { } void printNoConnectedDevices() { - printStatus('No connected devices.'); + printStatus(userMessages.flutterNoConnectedDevices); } @protected @@ -618,29 +614,11 @@ abstract class FlutterCommand extends Command { if (_requiresPubspecYaml && !PackageMap.isUsingCustomPackagesPath) { // Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path. if (!fs.isFileSync('pubspec.yaml')) { - throw ToolExit( - 'Error: No pubspec.yaml file found.\n' - 'This command should be run from the root of your Flutter project.\n' - 'Do not run this command from the root of your git clone of Flutter.' - ); + throw ToolExit(userMessages.flutterNoPubspec); } if (fs.isFileSync('flutter.yaml')) { - throw ToolExit( - 'Please merge your flutter.yaml into your pubspec.yaml.\n\n' - 'We have changed from having separate flutter.yaml and pubspec.yaml\n' - 'files to having just one pubspec.yaml file. Transitioning is simple:\n' - 'add a line that just says "flutter:" to your pubspec.yaml file, and\n' - 'move everything from your current flutter.yaml file into the\n' - 'pubspec.yaml file, below that line, with everything indented by two\n' - 'extra spaces compared to how it was in the flutter.yaml file. Then, if\n' - 'you had a "name:" line, move that to the top of your "pubspec.yaml"\n' - 'file (you may already have one there), so that there is only one\n' - '"name:" line. Finally, delete the flutter.yaml file.\n\n' - 'For an example of what a new-style pubspec.yaml file might look like,\n' - 'check out the Flutter Gallery pubspec.yaml:\n' - 'https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/pubspec.yaml\n' - ); + throw ToolExit(userMessages.flutterMergeYamlFiles); } // Validate the current package map only if we will not be running "pub get" later. @@ -654,7 +632,7 @@ abstract class FlutterCommand extends Command { if (_usesTargetOption) { final String targetPath = targetFile; if (!fs.isFileSync(targetPath)) - throw ToolExit('Target file "$targetPath" not found.'); + throw ToolExit(userMessages.flutterTargetFileMissing(targetPath)); } final bool dynamicFlag = argParser.options.containsKey('dynamic') @@ -667,15 +645,15 @@ abstract class FlutterCommand extends Command { ? argResults['patch'] : false; if (createBaseline && createPatch) - throw ToolExit('Error: Only one of --baseline, --patch is allowed.'); + throw ToolExit(userMessages.flutterBasePatchFlagsExclusive); if (createBaseline && !dynamicFlag) - throw ToolExit('Error: --baseline is allowed only when --dynamic is specified.'); + throw ToolExit(userMessages.flutterBaselineRequiresDynamic); if (createBaseline && compilationTraceFilePath == null) - throw ToolExit('Error: --baseline requires --compilation-trace-file to be specified.'); + throw ToolExit(userMessages.flutterBaselineRequiresTraceFile); if (createPatch && !dynamicFlag) - throw ToolExit('Error: --patch is allowed only when --dynamic is specified.'); + throw ToolExit(userMessages.flutterPatchRequiresDynamic); if (createPatch && compilationTraceFilePath == null) - throw ToolExit('Error: --patch requires --compilation-trace-file to be specified.'); + throw ToolExit(userMessages.flutterPatchRequiresTraceFile); } ApplicationPackageStore applicationPackages; diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index d6369a0659..dcc31987e4 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -24,6 +24,7 @@ import '../base/platform.dart'; import '../base/process.dart'; import '../base/process_manager.dart'; import '../base/terminal.dart'; +import '../base/user_messages.dart'; import '../base/utils.dart'; import '../cache.dart'; import '../dart/package_map.dart'; @@ -203,7 +204,7 @@ class FlutterCommandRunner extends CommandRunner { } catch (error) { // we don't have a logger at the time this is run // (which is why we don't use printTrace here) - print('Unable to locate flutter root: $error'); + print(userMessages.runnerNoRoot(error)); } return '.'; } @@ -261,12 +262,10 @@ class FlutterCommandRunner extends CommandRunner { try { wrapColumn = int.parse(topLevelResults['wrap-column']); if (wrapColumn < 0) { - throwToolExit('Argument to --wrap-column must be a positive integer. ' - 'You supplied ${topLevelResults['wrap-column']}.'); + throwToolExit(userMessages.runnerWrapColumnInvalid(topLevelResults['wrap-column'])); } } on FormatException { - throwToolExit('Unable to parse argument ' - '--wrap-column=${topLevelResults['wrap-column']}. Must be a positive integer.'); + throwToolExit(userMessages.runnerWrapColumnParseError(topLevelResults['wrap-column'])); } } @@ -310,11 +309,7 @@ class FlutterCommandRunner extends CommandRunner { addShutdownHook(() async { final File zipFile = getUniqueFile(fs.currentDirectory, 'bugreport', 'zip'); os.zip(tempDir, zipFile); - printStatus( - 'Bug report written to ${zipFile.basename}.\n' - 'Warning: this bug report contains local paths, device ' - 'identifiers, and log snippets.' - ); + printStatus(userMessages.runnerBugReportFinished(zipFile.basename)); }, ShutdownStage.POST_PROCESS_RECORDING); addShutdownHook(() => tempDir.delete(recursive: true), ShutdownStage.CLEANUP); } @@ -324,7 +319,7 @@ class FlutterCommandRunner extends CommandRunner { if (recordTo != null) { recordTo = recordTo.trim(); if (recordTo.isEmpty) - throwToolExit('record-to location not specified'); + throwToolExit(userMessages.runnerNoRecordTo); contextOverrides.addAll({ ProcessManager: getRecordingProcessManager(recordTo), FileSystem: getRecordingFileSystem(recordTo), @@ -336,7 +331,7 @@ class FlutterCommandRunner extends CommandRunner { if (replayFrom != null) { replayFrom = replayFrom.trim(); if (replayFrom.isEmpty) - throwToolExit('replay-from location not specified'); + throwToolExit(userMessages.runnerNoReplayFrom); contextOverrides.addAll({ ProcessManager: await getReplayProcessManager(replayFrom), FileSystem: getReplayFileSystem(replayFrom), @@ -430,18 +425,13 @@ class FlutterCommandRunner extends CommandRunner { engineSourcePath ??= _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src')); if (engineSourcePath == null) { - throwToolExit('Unable to detect local Flutter engine build directory.\n' - 'Either specify a dependency_override for the $kFlutterEnginePackageName package in your pubspec.yaml and ' - 'ensure --package-root is set if necessary, or set the \$$kFlutterEngineEnvironmentVariableName environment variable, or ' - 'use --local-engine-src-path to specify the path to the root of your flutter/engine repository.', + throwToolExit(userMessages.runnerNoEngineBuildDir(kFlutterEnginePackageName, kFlutterEngineEnvironmentVariableName), exitCode: 2); } } if (engineSourcePath != null && _tryEnginePath(engineSourcePath) == null) { - throwToolExit('Unable to detect a Flutter engine build directory in $engineSourcePath.\n' - 'Please ensure that $engineSourcePath is a Flutter engine \'src\' directory and that ' - 'you have compiled the engine in that directory, which should produce an \'out\' directory', + throwToolExit(userMessages.runnerNoEngineBuildDirInPath(engineSourcePath), exitCode: 2); } @@ -453,12 +443,12 @@ class FlutterCommandRunner extends CommandRunner { if (globalResults['local-engine'] != null) { localEngine = globalResults['local-engine']; } else { - throwToolExit('You must specify --local-engine if you are using a locally built engine.', exitCode: 2); + throwToolExit(userMessages.runnerLocalEngineRequired, exitCode: 2); } final String engineBuildPath = fs.path.normalize(fs.path.join(enginePath, 'out', localEngine)); if (!fs.isDirectorySync(engineBuildPath)) { - throwToolExit('No Flutter engine build found at $engineBuildPath.', exitCode: 2); + throwToolExit(userMessages.runnerNoEngineBuild(engineBuildPath), exitCode: 2); } // Determine the host engine directory associated with the local engine: @@ -519,13 +509,7 @@ class FlutterCommandRunner extends CommandRunner { while (directory.isNotEmpty) { if (_isDirectoryFlutterRepo(directory)) { if (!_compareResolvedPaths(directory, Cache.flutterRoot)) { - printError( - 'Warning: the \'flutter\' tool you are currently running is not the one from the current directory:\n' - ' running Flutter : ${Cache.flutterRoot}\n' - ' current directory: $directory\n' - 'This can happen when you have multiple copies of flutter installed. Please check your system path to verify ' - 'that you\'re running the expected version (run \'flutter --version\' to see which flutter is on your path).\n' - ); + printError(userMessages.runnerWrongFlutterInstance(Cache.flutterRoot, directory)); } break; @@ -548,28 +532,9 @@ class FlutterCommandRunner extends CommandRunner { final String flutterPath = fs.path.normalize(fs.file(rootUri).absolute.path); if (!fs.isDirectorySync(flutterPath)) { - printError( - 'Warning! This package referenced a Flutter repository via the .packages file that is ' - 'no longer available. The repository from which the \'flutter\' tool is currently ' - 'executing will be used instead.\n' - ' running Flutter tool: ${Cache.flutterRoot}\n' - ' previous reference : $flutterPath\n' - 'This can happen if you deleted or moved your copy of the Flutter repository, or ' - 'if it was on a volume that is no longer mounted or has been mounted at a ' - 'different location. Please check your system path to verify that you are running ' - 'the expected version (run \'flutter --version\' to see which flutter is on your path).\n' - ); + printError(userMessages.runnerRemovedFlutterRepo(Cache.flutterRoot, flutterPath)); } else if (!_compareResolvedPaths(flutterPath, Cache.flutterRoot)) { - printError( - 'Warning! The \'flutter\' tool you are currently running is from a different Flutter ' - 'repository than the one last used by this package. The repository from which the ' - '\'flutter\' tool is currently executing will be used instead.\n' - ' running Flutter tool: ${Cache.flutterRoot}\n' - ' previous reference : $flutterPath\n' - 'This can happen when you have multiple copies of flutter installed. Please check ' - 'your system path to verify that you are running the expected version (run ' - '\'flutter --version\' to see which flutter is on your path).\n' - ); + printError(userMessages.runnerChangedFlutterRepo(Cache.flutterRoot, flutterPath)); } } }