forked from firka/flutter
[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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user