feat(shorebird_cli): shorebird run -d support (#392)
This commit is contained in:
@@ -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 => [
|
||||
|
||||
Reference in New Issue
Block a user