[flutter_tool] Screenshot command must require device only for _kDeviceType (#44227)

There are cases where we have access to the observatory without having a device connection accessible.
This commit is contained in:
Kaushik Iska
2019-11-06 10:59:29 -08:00
committed by GitHub
parent 8cd892b39b
commit 8e8add524e
2 changed files with 44 additions and 9 deletions

View File

@@ -63,18 +63,27 @@ class ScreenshotCommand extends FlutterCommand {
Device device;
static void validateOptions(String screenshotType, Device device, String observatoryUri) {
switch (screenshotType) {
case _kDeviceType:
if (device == null) {
throwToolExit('Must have a connected device for screenshot type $screenshotType');
}
if (!device.supportsScreenshot) {
throwToolExit('Screenshot not supported for ${device.name}.');
}
break;
default:
if (observatoryUri == null) {
throwToolExit('Observatory URI must be specified for screenshot type $screenshotType');
}
}
}
@override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
device = await findTargetDevice();
if (device == null) {
throwToolExit('Must have a connected device');
}
if (argResults[_kType] == _kDeviceType && !device.supportsScreenshot) {
throwToolExit('Screenshot not supported for ${device.name}.');
}
if (argResults[_kType] != _kDeviceType && argResults[_kObservatoryUri] == null) {
throwToolExit('Observatory URI must be specified for screenshot type ${argResults[_kType]}');
}
validateOptions(argResults[_kType], device, argResults[_kObservatoryUri]);
return super.verifyThenRunCommand(commandPath);
}