run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  if (argResults!.rest.isEmpty) {
    logger.err('Flavor name is required.');
    return ExitCode.usage.code;
  }

  final flavor = argResults!.rest.first;
  final target = 'lib/main_$flavor.dart';

  logger.info('Running flavor: $flavor');

  // We replace the current process with flutter run
  // Simple Process.start to stream output would be better for interactive run

  final process = await Process.start('flutter', [
    'run',
    '--flavor',
    flavor,
    '-t',
    target,
  ], mode: ProcessStartMode.inheritStdio);

  final exitCode = await process.exitCode;
  return exitCode;
}