diff --git a/packages/shorebird_cli/lib/src/commands/run_command.dart b/packages/shorebird_cli/lib/src/commands/run_command.dart index 9f6990b0..b8cf30be 100644 --- a/packages/shorebird_cli/lib/src/commands/run_command.dart +++ b/packages/shorebird_cli/lib/src/commands/run_command.dart @@ -18,7 +18,13 @@ class RunCommand extends ShorebirdCommand super.auth, super.buildCodePushClient, super.validators, - }); + }) { + argParser.addOption( + 'device-id', + abbr: 'd', + help: 'Target device id or name.', + ); + } @override String get description => 'Run the Flutter application.'; @@ -36,12 +42,15 @@ class RunCommand extends ShorebirdCommand await logValidationIssues(); logger.info('Running app...'); + + final deviceId = results['device-id'] 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], ...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 be588566..9cceb3c0 100644 --- a/packages/shorebird_cli/test/src/commands/run_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/run_command_test.dart @@ -157,6 +157,41 @@ void main() { verify(() => logger.info(output)).called(1); }); + test('passes device-id when specified', () async { + final tempDir = Directory.systemTemp.createTempSync(); + + final progress = _MockProgress(); + when(() => logger.progress(any())).thenReturn(progress); + + const deviceId = 'test-device-id'; + when(() => argResults['device-id']).thenReturn(deviceId); + + when(() => process.stdout).thenAnswer((_) => const Stream.empty()); + when(() => process.stderr).thenAnswer((_) => const Stream.empty()); + when( + () => process.exitCode, + ).thenAnswer((_) async => ExitCode.success.code); + + final result = await IOOverrides.runZoned( + () => runCommand.run(), + getCurrentDirectory: () => tempDir, + ); + + final args = verify( + () => shorebirdProcess.start( + any(), + captureAny(), + runInShell: any(named: 'runInShell'), + ), + ).captured.first as List; + expect( + args, + equals(['run', '--release', '-d', deviceId]), + ); + + await expectLater(result, equals(ExitCode.success.code)); + }); + test('prints validation warnings', () async { when(() => flutterValidator.validate(any())).thenAnswer( (_) async => [