deviceUsername property

String get deviceUsername

Get the device username Check if the username is defined before the ip address in the ping command sample: username@192.168.1.1 If the ping command doesn't contain a username, then throw an error

Implementation

String get deviceUsername {
  final deviceIp = this.deviceIp;

  final targetSsh = uninstallCommand.firstWhere(
    (element) {
      if (element.contains(deviceIp)) {
        final username = element.split('@').first;

        if (username.isNotEmpty) return true;
      }
      return false;
    },
    orElse: () => throwToolExit(
      'Could not find the device username in the device config file',
    ),
  );

  return targetSsh.split('@').first;
}