Implementation of remoteDelete command, iteration 4

This commit is contained in:
adaptivegarage 2021-04-05 00:15:41 +02:00
parent c3e44fad81
commit 62a8cf4d85

View file

@ -26,13 +26,9 @@ public class RemoteDeleteCommand implements DbusCommand {
.required(true) .required(true)
.type(long.class) .type(long.class)
.help("Specify the timestamp of the message to delete."); .help("Specify the timestamp of the message to delete.");
var mut = subparser.addMutuallyExclusiveGroup() subparser.addArgument("-g", "--group")
.required(true);
mut.addArgument("-g", "--group")
.required(false)
.help("Specify the recipient group ID."); .help("Specify the recipient group ID.");
mut.addArgument("recipient") subparser.addArgument("recipient")
.required(false)
.help("Specify the recipients' phone number.").nargs("*"); .help("Specify the recipients' phone number.").nargs("*");
} }
@ -41,14 +37,10 @@ public class RemoteDeleteCommand implements DbusCommand {
final List<String> recipients = ns.getList("recipient"); final List<String> recipients = ns.getList("recipient");
final var groupIdString = ns.getString("group"); final var groupIdString = ns.getString("group");
// Possibly unnecessary (see above recipient(s) or group is required),
// but just for case...
final var noRecipients = recipients == null || recipients.isEmpty(); final var noRecipients = recipients == null || recipients.isEmpty();
if (noRecipients && groupIdString == null) { if (noRecipients && groupIdString == null) {
throw new UserErrorException("No recipients given"); throw new UserErrorException("No recipients given");
} }
// Possibly unnecessary (see above recipient(s) and group are mutually exclusive),
// but just for case...
if (!noRecipients && groupIdString != null) { if (!noRecipients && groupIdString != null) {
throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time"); throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
} }