buildCommand method

  1. @override
String buildCommand()
override

Build the @ command to be sent to remote secondary for execution.

Implementation

@override
String buildCommand() {
  if (isJson) {
    var updateParams = UpdateParams();
    var key = '';
    if (sharedWith != null) {
      key += '${VerbUtil.formatAtSign(sharedWith)}:';
    }
    key += atKey!;
    if (sharedBy != null) {
      key += '${VerbUtil.formatAtSign(sharedBy)}';
    }
    updateParams.atKey = key;
    updateParams.value = value;
    updateParams.sharedBy = sharedBy;
    updateParams.sharedWith = sharedWith;
    var metadata = Metadata();
    metadata.ttr = ttr;
    metadata.ttb = ttb;
    metadata.ttl = ttl;
    metadata.dataSignature = dataSignature;
    metadata.isEncrypted = isEncrypted;
    metadata.ccd = ccd;
    metadata.isPublic = isPublic;
    metadata.sharedKeyStatus = sharedKeyStatus;
    updateParams.metadata = metadata;
    var json = updateParams.toJson();
    var command = 'update:json:${jsonEncode(json)}\n';
    print('update json:$command');
    return command;
  }
  var command = 'update:';
  if (ttl != null) {
    command += 'ttl:$ttl:';
  }
  if (ttb != null) {
    command += 'ttb:$ttb:';
  }
  if (ttr != null) {
    command += 'ttr:$ttr:';
  }
  if (ccd != null) {
    command += 'ccd:$ccd:';
  }
  if (dataSignature != null) {
    command += 'dataSignature:$dataSignature:';
  }
  if (isBinary != null) {
    command += 'isBinary:$isBinary:';
  }
  if (isEncrypted != null) {
    command += 'isEncrypted:$isEncrypted:';
  }
  if (isPublic) {
    command += 'public:';
  } else if (sharedWith != null) {
    command += '${VerbUtil.formatAtSign(sharedWith)}:';
  }
  command += atKey!;

  if (sharedBy != null) {
    command += '${VerbUtil.formatAtSign(sharedBy)}';
  }
  if (value is String) {
    value = VerbUtil.replaceNewline(value);
  }
  command += ' $value\n';
  return command;
}