feat(shorebird_cli): shorebird run -d support (#392)

This commit is contained in:
Felix Angelov
2023-04-27 11:24:57 -05:00
committed by GitHub
parent 36a6f117cb
commit decd22cc8e
2 changed files with 45 additions and 1 deletions
@@ -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,
@@ -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<String>;
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 => [