Commit ec2d5833 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by Flutter GitHub Bot

Make subcommands return success instead of null (#48100)

parent a8c5f4e8
...@@ -88,7 +88,6 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -88,7 +88,6 @@ class AnalyzeCommand extends FlutterCommand {
runner.getRepoRoots(), runner.getRepoRoots(),
runner.getRepoPackages(), runner.getRepoPackages(),
).analyze(); ).analyze();
return null;
} else { } else {
await AnalyzeOnce( await AnalyzeOnce(
argResults, argResults,
...@@ -96,7 +95,7 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -96,7 +95,7 @@ class AnalyzeCommand extends FlutterCommand {
runner.getRepoPackages(), runner.getRepoPackages(),
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
).analyze(); ).analyze();
return null;
} }
return FlutterCommandResult.success();
} }
} }
...@@ -200,7 +200,7 @@ class AssembleCommand extends FlutterCommand { ...@@ -200,7 +200,7 @@ class AssembleCommand extends FlutterCommand {
final Depfile depfile = Depfile(result.inputFiles, result.outputFiles); final Depfile depfile = Depfile(result.inputFiles, result.outputFiles);
depfile.writeToFile(globals.fs.file(depfileFile)); depfile.writeToFile(globals.fs.file(depfileFile));
} }
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -178,7 +178,7 @@ class AttachCommand extends FlutterCommand { ...@@ -178,7 +178,7 @@ class AttachCommand extends FlutterCommand {
Artifacts: () => overrideArtifacts, Artifacts: () => overrideArtifacts,
}); });
return null; return FlutterCommandResult.success();
} }
Future<void> _attachToDevice(Device device) async { Future<void> _attachToDevice(Device device) async {
......
...@@ -119,7 +119,7 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -119,7 +119,7 @@ class BuildAarCommand extends BuildSubCommand {
outputDirectoryPath: stringArg('output-dir'), outputDirectoryPath: stringArg('output-dir'),
buildNumber: buildNumber, buildNumber: buildNumber,
); );
return null; return FlutterCommandResult.success();
} }
/// Returns the [FlutterProject] which is determined from the remaining command-line /// Returns the [FlutterProject] which is determined from the remaining command-line
......
...@@ -89,6 +89,6 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen ...@@ -89,6 +89,6 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
extraGenSnapshotOptions: stringsArg(FlutterOptions.kExtraGenSnapshotOptions), extraGenSnapshotOptions: stringsArg(FlutterOptions.kExtraGenSnapshotOptions),
dartDefines: dartDefines, dartDefines: dartDefines,
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -112,6 +112,6 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -112,6 +112,6 @@ class BuildApkCommand extends BuildSubCommand {
target: targetFile, target: targetFile,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -83,6 +83,6 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -83,6 +83,6 @@ class BuildAppBundleCommand extends BuildSubCommand {
target: targetFile, target: targetFile,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -139,6 +139,6 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -139,6 +139,6 @@ class BuildBundleCommand extends BuildSubCommand {
fileSystemScheme: stringArg('filesystem-scheme'), fileSystemScheme: stringArg('filesystem-scheme'),
fileSystemRoots: stringsArg('filesystem-root'), fileSystemRoots: stringsArg('filesystem-root'),
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -69,6 +69,6 @@ class BuildFuchsiaCommand extends BuildSubCommand { ...@@ -69,6 +69,6 @@ class BuildFuchsiaCommand extends BuildSubCommand {
buildInfo: buildInfo, buildInfo: buildInfo,
runnerPackageSource: stringArg('runner-source'), runnerPackageSource: stringArg('runner-source'),
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -92,6 +92,6 @@ class BuildIOSCommand extends BuildSubCommand { ...@@ -92,6 +92,6 @@ class BuildIOSCommand extends BuildSubCommand {
globals.printStatus('Built ${result.output}.'); globals.printStatus('Built ${result.output}.');
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -204,8 +204,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -204,8 +204,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
} }
globals.printStatus('Frameworks written to ${outputDirectory.path}.'); globals.printStatus('Frameworks written to ${outputDirectory.path}.');
return FlutterCommandResult.success();
return null;
} }
/// Create podspec that will download and unzip remote engine assets so host apps can leverage CocoaPods /// Create podspec that will download and unzip remote engine assets so host apps can leverage CocoaPods
......
...@@ -47,6 +47,6 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -47,6 +47,6 @@ class BuildLinuxCommand extends BuildSubCommand {
throwToolExit('"build linux" only supported on Linux hosts.'); throwToolExit('"build linux" only supported on Linux hosts.');
} }
await buildLinux(flutterProject.linux, buildInfo, target: targetFile); await buildLinux(flutterProject.linux, buildInfo, target: targetFile);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -51,6 +51,6 @@ class BuildMacosCommand extends BuildSubCommand { ...@@ -51,6 +51,6 @@ class BuildMacosCommand extends BuildSubCommand {
buildInfo: buildInfo, buildInfo: buildInfo,
targetOverride: targetFile, targetOverride: targetFile,
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -67,6 +67,6 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -67,6 +67,6 @@ class BuildWebCommand extends BuildSubCommand {
dartDefines, dartDefines,
boolArg('csp') boolArg('csp')
); );
return null; return FlutterCommandResult.success();
} }
} }
...@@ -47,6 +47,6 @@ class BuildWindowsCommand extends BuildSubCommand { ...@@ -47,6 +47,6 @@ class BuildWindowsCommand extends BuildSubCommand {
throwToolExit('"build windows" only supported on Windows hosts.'); throwToolExit('"build windows" only supported on Windows hosts.');
} }
await buildWindows(flutterProject.windows, buildInfo, target: targetFile); await buildWindows(flutterProject.windows, buildInfo, target: targetFile);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -42,10 +42,10 @@ class ChannelCommand extends FlutterCommand { ...@@ -42,10 +42,10 @@ class ChannelCommand extends FlutterCommand {
showAll: boolArg('all'), showAll: boolArg('all'),
verbose: globalResults['verbose'] as bool, verbose: globalResults['verbose'] as bool,
); );
return null; return FlutterCommandResult.success();
case 1: case 1:
await _switchChannel(argResults.rest[0]); await _switchChannel(argResults.rest[0]);
return null; return FlutterCommandResult.success();
default: default:
throw ToolExit('Too many arguments.\n$usage'); throw ToolExit('Too many arguments.\n$usage');
} }
......
...@@ -101,7 +101,7 @@ class ConfigCommand extends FlutterCommand { ...@@ -101,7 +101,7 @@ class ConfigCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
if (boolArg('machine')) { if (boolArg('machine')) {
await handleMachine(); await handleMachine();
return null; return FlutterCommandResult.success();
} }
if (boolArg('clear-features')) { if (boolArg('clear-features')) {
...@@ -110,7 +110,7 @@ class ConfigCommand extends FlutterCommand { ...@@ -110,7 +110,7 @@ class ConfigCommand extends FlutterCommand {
globals.config.removeValue(feature.configSetting); globals.config.removeValue(feature.configSetting);
} }
} }
return null; return FlutterCommandResult.success();
} }
if (argResults.wasParsed('analytics')) { if (argResults.wasParsed('analytics')) {
...@@ -157,7 +157,7 @@ class ConfigCommand extends FlutterCommand { ...@@ -157,7 +157,7 @@ class ConfigCommand extends FlutterCommand {
globals.printStatus('\nYou may need to restart any open editors for them to read new settings.'); globals.printStatus('\nYou may need to restart any open editors for them to read new settings.');
} }
return null; return FlutterCommandResult.success();
} }
Future<void> handleMachine() async { Future<void> handleMachine() async {
......
...@@ -297,7 +297,7 @@ class CreateCommand extends FlutterCommand { ...@@ -297,7 +297,7 @@ class CreateCommand extends FlutterCommand {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await _writeSamplesJson(stringArg('list-samples')); await _writeSamplesJson(stringArg('list-samples'));
return null; return FlutterCommandResult.success();
} }
if (argResults.rest.isEmpty) { if (argResults.rest.isEmpty) {
...@@ -482,8 +482,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -482,8 +482,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
globals.printStatus('Your $application code is in $relativeAppMain'); globals.printStatus('Your $application code is in $relativeAppMain');
} }
} }
return FlutterCommandResult.success();
return null;
} }
Future<int> _generateModule(Directory directory, Map<String, dynamic> templateContext, { bool overwrite = false }) async { Future<int> _generateModule(Directory directory, Map<String, dynamic> templateContext, { bool overwrite = false }) async {
......
...@@ -74,7 +74,7 @@ class DaemonCommand extends FlutterCommand { ...@@ -74,7 +74,7 @@ class DaemonCommand extends FlutterCommand {
Logger: () => notifyingLogger, Logger: () => notifyingLogger,
}, },
); );
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -47,6 +47,6 @@ class DevicesCommand extends FlutterCommand { ...@@ -47,6 +47,6 @@ class DevicesCommand extends FlutterCommand {
await Device.printDevices(devices); await Device.printDevices(devices);
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -185,7 +185,7 @@ class DriveCommand extends RunCommandBase { ...@@ -185,7 +185,7 @@ class DriveCommand extends RunCommandBase {
} }
} }
return null; return FlutterCommandResult.success();
} }
String _getTestFile() { String _getTestFile() {
......
...@@ -54,7 +54,7 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -54,7 +54,7 @@ class EmulatorsCommand extends FlutterCommand {
await _listEmulators(searchText); await _listEmulators(searchText);
} }
return null; return FlutterCommandResult.success();
} }
Future<void> _launchEmulator(String id) async { Future<void> _launchEmulator(String id) async {
......
...@@ -76,6 +76,6 @@ class FormatCommand extends FlutterCommand { ...@@ -76,6 +76,6 @@ class FormatCommand extends FlutterCommand {
throwToolExit('Formatting failed: $result', exitCode: result); throwToolExit('Formatting failed: $result', exitCode: result);
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -31,7 +31,7 @@ class GenerateCommand extends FlutterCommand { ...@@ -31,7 +31,7 @@ class GenerateCommand extends FlutterCommand {
globals.printError('Code generation failed.'); globals.printError('Code generation failed.');
break; break;
} }
if (codegenStatus ==CodegenStatus.Succeeded) { if (codegenStatus == CodegenStatus.Succeeded) {
break; break;
} }
} }
...@@ -41,7 +41,7 @@ class GenerateCommand extends FlutterCommand { ...@@ -41,7 +41,7 @@ class GenerateCommand extends FlutterCommand {
return dir.childDirectory('error_cache').existsSync(); return dir.childDirectory('error_cache').existsSync();
}, orElse: () => null); }, orElse: () => null);
if (errorCacheParent == null) { if (errorCacheParent == null) {
return null; return FlutterCommandResult.success();
} }
final Directory errorCache = errorCacheParent.childDirectory('error_cache'); final Directory errorCache = errorCacheParent.childDirectory('error_cache');
for (final File errorFile in errorCache.listSync(recursive: true).whereType<File>()) { for (final File errorFile in errorCache.listSync(recursive: true).whereType<File>()) {
...@@ -56,6 +56,6 @@ class GenerateCommand extends FlutterCommand { ...@@ -56,6 +56,6 @@ class GenerateCommand extends FlutterCommand {
globals.printError('Error reading error in ${errorFile.path}'); globals.printError('Error reading error in ${errorFile.path}');
} }
} }
return const FlutterCommandResult(ExitStatus.fail); return FlutterCommandResult.fail();
} }
} }
...@@ -219,7 +219,7 @@ class IdeConfigCommand extends FlutterCommand { ...@@ -219,7 +219,7 @@ class IdeConfigCommand extends FlutterCommand {
if (boolArg('update-templates')) { if (boolArg('update-templates')) {
_handleTemplateUpdate(); _handleTemplateUpdate();
return null; return FlutterCommandResult.success();
} }
final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot); final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot);
...@@ -243,7 +243,7 @@ class IdeConfigCommand extends FlutterCommand { ...@@ -243,7 +243,7 @@ class IdeConfigCommand extends FlutterCommand {
globals.printStatus('Your IntelliJ configuration is now up to date. It is prudent to ' globals.printStatus('Your IntelliJ configuration is now up to date. It is prudent to '
'restart IntelliJ, if running.'); 'restart IntelliJ, if running.');
return null; return FlutterCommandResult.success();
} }
int _renderTemplate(String templateName, String dirPath, Map<String, dynamic> context) { int _renderTemplate(String templateName, String dirPath, Map<String, dynamic> context) {
......
...@@ -38,6 +38,6 @@ class InjectPluginsCommand extends FlutterCommand { ...@@ -38,6 +38,6 @@ class InjectPluginsCommand extends FlutterCommand {
globals.printStatus('This project does not use plugins, no GeneratedPluginRegistrants have been created.'); globals.printStatus('This project does not use plugins, no GeneratedPluginRegistrants have been created.');
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -45,7 +45,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -45,7 +45,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
throwToolExit('Install failed'); throwToolExit('Install failed');
} }
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -83,6 +83,6 @@ class LogsCommand extends FlutterCommand { ...@@ -83,6 +83,6 @@ class LogsCommand extends FlutterCommand {
throwToolExit('Error listening to $logReader logs.'); throwToolExit('Error listening to $logReader logs.');
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -60,6 +60,6 @@ class MakeHostAppEditableCommand extends FlutterCommand { ...@@ -60,6 +60,6 @@ class MakeHostAppEditableCommand extends FlutterCommand {
await _project.ios.makeHostAppEditable(); await _project.ios.makeHostAppEditable();
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -131,7 +131,7 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -131,7 +131,7 @@ class PackagesGetCommand extends FlutterCommand {
await exampleProject.ensureReadyForPlatformSpecificTooling(checkProjects: true); await exampleProject.ensureReadyForPlatformSpecificTooling(checkProjects: true);
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -162,7 +162,7 @@ class PackagesTestCommand extends FlutterCommand { ...@@ -162,7 +162,7 @@ class PackagesTestCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.batch(<String>['run', 'test', ...argResults.rest], context: PubContext.runTest, retry: false); await pub.batch(<String>['run', 'test', ...argResults.rest], context: PubContext.runTest, retry: false);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -203,7 +203,7 @@ class PackagesPublishCommand extends FlutterCommand { ...@@ -203,7 +203,7 @@ class PackagesPublishCommand extends FlutterCommand {
]; ];
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(<String>['publish', ...args]); await pub.interactively(<String>['publish', ...args]);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -234,7 +234,7 @@ class PackagesForwardCommand extends FlutterCommand { ...@@ -234,7 +234,7 @@ class PackagesForwardCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(<String>[_commandName, ...argResults.rest]); await pub.interactively(<String>[_commandName, ...argResults.rest]);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -262,6 +262,6 @@ class PackagesPassthroughCommand extends FlutterCommand { ...@@ -262,6 +262,6 @@ class PackagesPassthroughCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly(); Cache.releaseLockEarly();
await pub.interactively(argResults.rest); await pub.interactively(argResults.rest);
return null; return FlutterCommandResult.success();
} }
} }
...@@ -88,6 +88,6 @@ class PrecacheCommand extends FlutterCommand { ...@@ -88,6 +88,6 @@ class PrecacheCommand extends FlutterCommand {
} else { } else {
globals.printStatus('Already up-to-date.'); globals.printStatus('Already up-to-date.');
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -97,16 +97,16 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -97,16 +97,16 @@ class ScreenshotCommand extends FlutterCommand {
switch (stringArg(_kType)) { switch (stringArg(_kType)) {
case _kDeviceType: case _kDeviceType:
await runScreenshot(outputFile); await runScreenshot(outputFile);
return null; return FlutterCommandResult.success();
case _kSkiaType: case _kSkiaType:
await runSkia(outputFile); await runSkia(outputFile);
return null; return FlutterCommandResult.success();
case _kRasterizerType: case _kRasterizerType:
await runRasterizer(outputFile); await runRasterizer(outputFile);
return null; return FlutterCommandResult.success();
} }
return null; return FlutterCommandResult.success();
} }
Future<void> runScreenshot(File outputFile) async { Future<void> runScreenshot(File outputFile) async {
......
...@@ -50,7 +50,7 @@ class ShellCompletionCommand extends FlutterCommand { ...@@ -50,7 +50,7 @@ class ShellCompletionCommand extends FlutterCommand {
if (argResults.rest.isEmpty || argResults.rest.first == '-') { if (argResults.rest.isEmpty || argResults.rest.first == '-') {
stdout.write(generateCompletionScript(<String>['flutter'])); stdout.write(generateCompletionScript(<String>['flutter']));
return null; return FlutterCommandResult.warning();
} }
final File outputFile = globals.fs.file(argResults.rest.first); final File outputFile = globals.fs.file(argResults.rest.first);
...@@ -67,6 +67,6 @@ class ShellCompletionCommand extends FlutterCommand { ...@@ -67,6 +67,6 @@ class ShellCompletionCommand extends FlutterCommand {
throwToolExit('Unable to write shell completion setup script.\n$error', exitCode: 1); throwToolExit('Unable to write shell completion setup script.\n$error', exitCode: 1);
} }
return null; return FlutterCommandResult.success();
} }
} }
...@@ -270,7 +270,7 @@ class TestCommand extends FastFlutterCommand { ...@@ -270,7 +270,7 @@ class TestCommand extends FastFlutterCommand {
if (result != 0) { if (result != 0) {
throwToolExit(null); throwToolExit(null);
} }
return const FlutterCommandResult(ExitStatus.success); return FlutterCommandResult.success();
} }
Future<void> _buildTestAsset() async { Future<void> _buildTestAsset() async {
......
...@@ -22,6 +22,6 @@ class TrainingCommand extends FlutterCommand { ...@@ -22,6 +22,6 @@ class TrainingCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
// This command does not do anything yet :). // This command does not do anything yet :).
return null; return FlutterCommandResult.success();
} }
} }
...@@ -93,7 +93,7 @@ class UnpackCommand extends FlutterCommand { ...@@ -93,7 +93,7 @@ class UnpackCommand extends FlutterCommand {
if (!success) { if (!success) {
throwToolExit('Failed to unpack desktop artifacts.'); throwToolExit('Failed to unpack desktop artifacts.');
} }
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -180,7 +180,7 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -180,7 +180,7 @@ class UpdatePackagesCommand extends FlutterCommand {
); );
} }
globals.printStatus('All pubspecs were up to date.'); globals.printStatus('All pubspecs were up to date.');
return null; return FlutterCommandResult.success();
} }
if (upgrade || isPrintPaths || isPrintTransitiveClosure) { if (upgrade || isPrintPaths || isPrintTransitiveClosure) {
...@@ -289,12 +289,12 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -289,12 +289,12 @@ class UpdatePackagesCommand extends FlutterCommand {
tree._dependencyTree.forEach((String from, Set<String> to) { tree._dependencyTree.forEach((String from, Set<String> to) {
globals.printStatus('$from -> $to'); globals.printStatus('$from -> $to');
}); });
return null; return FlutterCommandResult.success();
} }
if (isPrintPaths) { if (isPrintPaths) {
showDependencyPaths(from: stringArg('from'), to: stringArg('to'), tree: tree); showDependencyPaths(from: stringArg('from'), to: stringArg('to'), tree: tree);
return null; return FlutterCommandResult.success();
} }
// Now that we have collected all the data, we can apply our dependency // Now that we have collected all the data, we can apply our dependency
...@@ -328,7 +328,7 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -328,7 +328,7 @@ class UpdatePackagesCommand extends FlutterCommand {
final double seconds = timer.elapsedMilliseconds / 1000.0; final double seconds = timer.elapsedMilliseconds / 1000.0;
globals.printStatus('\nRan \'pub\' $count time${count == 1 ? "" : "s"} and fetched coverage data in ${seconds.toStringAsFixed(1)}s.'); globals.printStatus('\nRan \'pub\' $count time${count == 1 ? "" : "s"} and fetched coverage data in ${seconds.toStringAsFixed(1)}s.');
return null; return FlutterCommandResult.success();
} }
void showDependencyPaths({ void showDependencyPaths({
......
...@@ -50,14 +50,13 @@ class UpgradeCommand extends FlutterCommand { ...@@ -50,14 +50,13 @@ class UpgradeCommand extends FlutterCommand {
bool get shouldUpdateCache => false; bool get shouldUpdateCache => false;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() {
await _commandRunner.runCommand( return _commandRunner.runCommand(
boolArg('force'), boolArg('force'),
boolArg('continue'), boolArg('continue'),
GitTagVersion.determine(), GitTagVersion.determine(),
FlutterVersion.instance, FlutterVersion.instance,
); );
return null;
} }
} }
...@@ -74,7 +73,7 @@ class UpgradeCommandRunner { ...@@ -74,7 +73,7 @@ class UpgradeCommandRunner {
} else { } else {
await runCommandSecondHalf(flutterVersion); await runCommandSecondHalf(flutterVersion);
} }
return null; return FlutterCommandResult.success();
} }
Future<void> runCommandFirstHalf( Future<void> runCommandFirstHalf(
......
...@@ -143,6 +143,6 @@ class VersionCommand extends FlutterCommand { ...@@ -143,6 +143,6 @@ class VersionCommand extends FlutterCommand {
throwToolExit(null, exitCode: code); throwToolExit(null, exitCode: code);
} }
return const FlutterCommandResult(ExitStatus.success); return FlutterCommandResult.success();
} }
} }
...@@ -171,7 +171,9 @@ class BuildEvent extends UsageEvent { ...@@ -171,7 +171,9 @@ class BuildEvent extends UsageEvent {
/// An event that reports the result of a top-level command. /// An event that reports the result of a top-level command.
class CommandResultEvent extends UsageEvent { class CommandResultEvent extends UsageEvent {
CommandResultEvent(String commandPath, FlutterCommandResult result) CommandResultEvent(String commandPath, FlutterCommandResult result)
: super(commandPath, result?.toString() ?? 'unspecified'); : assert(commandPath != null),
assert(result != null),
super(commandPath, result.toString());
@override @override
void send() { void send() {
......
...@@ -50,6 +50,21 @@ class FlutterCommandResult { ...@@ -50,6 +50,21 @@ class FlutterCommandResult {
this.endTimeOverride, this.endTimeOverride,
}); });
/// A command that succeeded. It is used to log the result of a command invocation.
factory FlutterCommandResult.success() {
return const FlutterCommandResult(ExitStatus.success);
}
/// A command that exited with a warning. It is used to log the result of a command invocation.
factory FlutterCommandResult.warning() {
return const FlutterCommandResult(ExitStatus.warning);
}
/// A command that failed. It is used to log the result of a command invocation.
factory FlutterCommandResult.fail() {
return const FlutterCommandResult(ExitStatus.fail);
}
final ExitStatus exitStatus; final ExitStatus exitStatus;
/// Optional data that can be appended to the timing event. /// Optional data that can be appended to the timing event.
...@@ -516,12 +531,9 @@ abstract class FlutterCommand extends Command<void> { ...@@ -516,12 +531,9 @@ abstract class FlutterCommand extends Command<void> {
flutterUsage.printWelcome(); flutterUsage.printWelcome();
final String commandPath = await usagePath; final String commandPath = await usagePath;
_registerSignalHandlers(commandPath, startTime); _registerSignalHandlers(commandPath, startTime);
FlutterCommandResult commandResult; FlutterCommandResult commandResult = FlutterCommandResult.fail();
try { try {
commandResult = await verifyThenRunCommand(commandPath); commandResult = await verifyThenRunCommand(commandPath);
} on ToolExit {
commandResult = const FlutterCommandResult(ExitStatus.fail);
rethrow;
} finally { } finally {
final DateTime endTime = systemClock.now(); final DateTime endTime = systemClock.now();
globals.printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime)))); globals.printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime))));
...@@ -557,15 +569,15 @@ abstract class FlutterCommand extends Command<void> { ...@@ -557,15 +569,15 @@ abstract class FlutterCommand extends Command<void> {
if (commandPath == null) { if (commandPath == null) {
return; return;
} }
assert(commandResult != null);
// Send command result. // Send command result.
CommandResultEvent(commandPath, commandResult).send(); CommandResultEvent(commandPath, commandResult).send();
// Send timing. // Send timing.
final List<String> labels = <String>[ final List<String> labels = <String>[
if (commandResult?.exitStatus != null) if (commandResult.exitStatus != null)
getEnumName(commandResult.exitStatus), getEnumName(commandResult.exitStatus),
if (commandResult?.timingLabelParts?.isNotEmpty ?? false) if (commandResult.timingLabelParts?.isNotEmpty ?? false)
...commandResult.timingLabelParts, ...commandResult.timingLabelParts,
]; ];
...@@ -577,7 +589,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -577,7 +589,7 @@ abstract class FlutterCommand extends Command<void> {
name, name,
// If the command provides its own end time, use it. Otherwise report // If the command provides its own end time, use it. Otherwise report
// the duration of the entire execution. // the duration of the entire execution.
(commandResult?.endTimeOverride ?? endTime).difference(startTime), (commandResult.endTimeOverride ?? endTime).difference(startTime),
// Report in the form of `success-[parameter1-parameter2]`, all of which // Report in the form of `success-[parameter1-parameter2]`, all of which
// can be null if the command doesn't provide a FlutterCommandResult. // can be null if the command doesn't provide a FlutterCommandResult.
label: label == '' ? null : label, label: label == '' ? null : label,
......
...@@ -75,7 +75,7 @@ void main() { ...@@ -75,7 +75,7 @@ void main() {
const GitTagVersion.unknown(), const GitTagVersion.unknown(),
flutterVersion, flutterVersion,
); );
expect(await result, null); expect(await result, FlutterCommandResult.success());
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => processManager, ProcessManager: () => processManager,
Platform: () => fakePlatform, Platform: () => fakePlatform,
...@@ -103,7 +103,7 @@ void main() { ...@@ -103,7 +103,7 @@ void main() {
gitTagVersion, gitTagVersion,
flutterVersion, flutterVersion,
); );
expect(await result, null); expect(await result, FlutterCommandResult.success());
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => processManager, ProcessManager: () => processManager,
Platform: () => fakePlatform, Platform: () => fakePlatform,
...@@ -116,7 +116,7 @@ void main() { ...@@ -116,7 +116,7 @@ void main() {
gitTagVersion, gitTagVersion,
flutterVersion, flutterVersion,
); );
expect(await result, null); expect(await result, FlutterCommandResult.success());
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => processManager, ProcessManager: () => processManager,
Platform: () => fakePlatform, Platform: () => fakePlatform,
...@@ -130,7 +130,7 @@ void main() { ...@@ -130,7 +130,7 @@ void main() {
gitTagVersion, gitTagVersion,
flutterVersion, flutterVersion,
); );
expect(await result, null); expect(await result, FlutterCommandResult.success());
verifyNever(globals.processManager.start( verifyNever(globals.processManager.start(
<String>[ <String>[
globals.fs.path.join('bin', 'flutter'), globals.fs.path.join('bin', 'flutter'),
......
...@@ -24,10 +24,12 @@ import '../../src/mocks.dart'; ...@@ -24,10 +24,12 @@ import '../../src/mocks.dart';
void main() { void main() {
Cache.disableLocking(); Cache.disableLocking();
group('getUsage', () { group('Usage', () {
Directory tempDir; Directory tempDir;
Usage mockUsage;
setUp(() { setUp(() {
mockUsage = MockUsage();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.'); tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
}); });
...@@ -83,6 +85,26 @@ void main() { ...@@ -83,6 +85,26 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(), AndroidBuilder: () => FakeAndroidBuilder(),
}); });
testUsingContext('logs success', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
await runCommandIn(projectPath,
arguments: <String>['--target-platform=android-arm']);
verify(mockUsage.sendEvent(
'tool-command-result',
'aar',
label: 'success',
value: anyNamed('value'),
parameters: anyNamed('parameters'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Usage: () => mockUsage,
});
}); });
group('Gradle', () { group('Gradle', () {
......
...@@ -26,10 +26,12 @@ import '../../src/mocks.dart'; ...@@ -26,10 +26,12 @@ import '../../src/mocks.dart';
void main() { void main() {
Cache.disableLocking(); Cache.disableLocking();
group('getUsage', () { group('Usage', () {
Directory tempDir; Directory tempDir;
Usage mockUsage;
setUp(() { setUp(() {
mockUsage = MockUsage();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.'); tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
}); });
...@@ -92,6 +94,25 @@ void main() { ...@@ -92,6 +94,25 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(), AndroidBuilder: () => FakeAndroidBuilder(),
}); });
testUsingContext('logs success', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
await runBuildApkCommand(projectPath);
verify(mockUsage.sendEvent(
'tool-command-result',
'apk',
label: 'success',
value: anyNamed('value'),
parameters: anyNamed('parameters'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Usage: () => mockUsage,
});
}); });
group('Gradle', () { group('Gradle', () {
......
...@@ -26,11 +26,13 @@ import '../../src/mocks.dart'; ...@@ -26,11 +26,13 @@ import '../../src/mocks.dart';
void main() { void main() {
Cache.disableLocking(); Cache.disableLocking();
group('getUsage', () { group('Usage', () {
Directory tempDir; Directory tempDir;
Usage mockUsage;
setUp(() { setUp(() {
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.'); tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
mockUsage = MockUsage();
}); });
tearDown(() { tearDown(() {
...@@ -75,6 +77,25 @@ void main() { ...@@ -75,6 +77,25 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(), AndroidBuilder: () => FakeAndroidBuilder(),
}); });
testUsingContext('logs success', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
await runBuildAppBundleCommand(projectPath);
verify(mockUsage.sendEvent(
'tool-command-result',
'appbundle',
label: 'success',
value: anyNamed('value'),
parameters: anyNamed('parameters'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Usage: () => mockUsage,
});
}); });
group('Gradle', () { group('Gradle', () {
......
...@@ -342,7 +342,7 @@ class _CrashCommand extends FlutterCommand { ...@@ -342,7 +342,7 @@ class _CrashCommand extends FlutterCommand {
fn3(); fn3();
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -217,6 +217,14 @@ void main() { ...@@ -217,6 +217,14 @@ void main() {
} }
}); });
test('FlutterCommandResult.success()', () async {
expect(FlutterCommandResult.success().exitStatus, ExitStatus.success);
});
test('FlutterCommandResult.warning()', () async {
expect(FlutterCommandResult.warning().exitStatus, ExitStatus.warning);
});
group('signals tests', () { group('signals tests', () {
MockIoProcessSignal mockSignal; MockIoProcessSignal mockSignal;
ProcessSignal signalUnderTest; ProcessSignal signalUnderTest;
...@@ -297,7 +305,7 @@ void main() { ...@@ -297,7 +305,7 @@ void main() {
'flutter', 'flutter',
'dummy', 'dummy',
const Duration(milliseconds: 1000), const Duration(milliseconds: 1000),
null, 'fail',
], ],
); );
}); });
...@@ -388,7 +396,7 @@ class FakeCommand extends FlutterCommand { ...@@ -388,7 +396,7 @@ class FakeCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
return null; return FlutterCommandResult.success();
} }
} }
......
...@@ -36,7 +36,7 @@ class DummyFlutterCommand extends FlutterCommand { ...@@ -36,7 +36,7 @@ class DummyFlutterCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
return commandFunction == null ? null : await commandFunction(); return commandFunction == null ? FlutterCommandResult.fail() : await commandFunction();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment