run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<int> run() async {
return handleRuntimeErrors(() async {
final args = argResults?.rest;
final arg0 = args?.firstOrNull;
final platform = SupportedPlatform.current;
String projectDir = arg0 ?? '';
projectDir = p.normalize(p.absolute(projectDir));
// if no project directory is provided, show usage
if (projectDir.isEmpty) {
printUsage();
return ExitCode.success.code;
}
header('Run', message: description);
await PathValidationTask(projectDir).run();
line();
await CheckPubspecTask(projectDir).run();
line();
final process = await LaunchAppTask(projectDir, platform).run();
if (process != null) {
line();
await process.stdout.listenVerbose();
await process.stderr.listenErrors();
}
final exitCode = await process?.exitCode ?? ExitCode.success.code;
if (exitCode != 0) {
return finishWithError(
'Failure',
message: 'Failed to launch GUI on [$platform]',
exitCode: exitCode,
stackTrace: StackTrace.current,
);
}
return finishSuccesfuly(
'Success',
message: 'GUI Launched on [$platform]',
);
});
}