tryPingDevice method
Implementation
Future<bool> tryPingDevice(String pingTarget, bool ipv6) async {
final spinner = interaction.spinner(
inProgressMessage: 'Pinging device to check if it is reachable',
doneMessage: 'Pinging device completed',
failedMessage: 'Pinging device failed',
);
await Future.delayed(Duration(seconds: 2));
final RunResult? result = await processRunner.runCommand(
hostPlatform.pingCommand(ipv6: ipv6, pingTarget: pingTarget),
parseResult: (result) => result,
parseFail: (e, s) {
logger.info(
'Something went wrong while pinging the device.',
);
logger.detail(
'Exception: $e \nStack: $s',
);
return null;
},
spinner: spinner,
label: 'pingCommand',
logger: logger,
);
if (result == null || result.exitCode != 0) {
return false;
}
// If the user doesn't configure a ping success regex, any ping with exitCode zero
// is good enough. Otherwise we check if either stdout or stderr have a match of
// the pingSuccessRegex.
final RegExp? pingSuccessRegex = hostPlatform.pingSuccessRegex;
return pingSuccessRegex == null ||
pingSuccessRegex.hasMatch(result.stdout) ||
pingSuccessRegex.hasMatch(result.stderr);
}