From f2a3dea8ea511b069dc1556b421ada38320d5aeb Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Mon, 1 May 2023 14:04:59 -0500 Subject: [PATCH] feat(shorebird_cli): `shorebird run` support `--flavor` and `--target` (#416) --- .../lib/src/commands/run_command.dart | 26 ++++++++++++++----- .../test/src/commands/run_command_test.dart | 14 ++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/run_command.dart b/packages/shorebird_cli/lib/src/commands/run_command.dart index b8cf30be..281d5fc2 100644 --- a/packages/shorebird_cli/lib/src/commands/run_command.dart +++ b/packages/shorebird_cli/lib/src/commands/run_command.dart @@ -19,11 +19,21 @@ class RunCommand extends ShorebirdCommand super.buildCodePushClient, super.validators, }) { - argParser.addOption( - 'device-id', - abbr: 'd', - help: 'Target device id or name.', - ); + argParser + ..addOption( + 'device-id', + abbr: 'd', + help: 'Target device id or name.', + ) + ..addOption( + 'target', + abbr: 't', + help: 'The main entrypoint file of the application.', + ) + ..addOption( + 'flavor', + help: 'The product flavor to use when building the app.', + ); } @override @@ -44,13 +54,17 @@ class RunCommand extends ShorebirdCommand logger.info('Running app...'); final deviceId = results['device-id'] as String?; + final flavor = results['flavor'] as String?; + final target = results['target'] as String?; final flutter = await process.start( 'flutter', [ 'run', // Eventually we should support running in both debug and release mode. '--release', - if (deviceId != null) ...['-d', deviceId], + if (deviceId != null) '--device-id=$deviceId', + if (flavor != null) '--flavor=$flavor', + if (target != null) '--target=$target', ...results.rest ], runInShell: true, diff --git a/packages/shorebird_cli/test/src/commands/run_command_test.dart b/packages/shorebird_cli/test/src/commands/run_command_test.dart index 9cceb3c0..4bf6e0a6 100644 --- a/packages/shorebird_cli/test/src/commands/run_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/run_command_test.dart @@ -157,14 +157,18 @@ void main() { verify(() => logger.info(output)).called(1); }); - test('passes device-id when specified', () async { + test('passes additional args when specified', () async { final tempDir = Directory.systemTemp.createTempSync(); final progress = _MockProgress(); when(() => logger.progress(any())).thenReturn(progress); const deviceId = 'test-device-id'; + const flavor = 'development'; + const target = './lib/main_development.dart'; when(() => argResults['device-id']).thenReturn(deviceId); + when(() => argResults['flavor']).thenReturn(flavor); + when(() => argResults['target']).thenReturn(target); when(() => process.stdout).thenAnswer((_) => const Stream.empty()); when(() => process.stderr).thenAnswer((_) => const Stream.empty()); @@ -186,7 +190,13 @@ void main() { ).captured.first as List; expect( args, - equals(['run', '--release', '-d', deviceId]), + equals([ + 'run', + '--release', + '--device-id=$deviceId', + '--flavor=$flavor', + '--target=$target', + ]), ); await expectLater(result, equals(ExitCode.success.code));