- public int handleCommand(final Namespace ns, final Signal signal) {
- if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && (
- ns.getBoolean("endsession") || ns.getString("group") == null
- )) {
- System.err.println("No recipients given");
- System.err.println("Aborting sending.");
- return 1;
- }
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
+ final var isNoteToSelf = ns.getBoolean("note-to-self");
+ final var recipientStrings = ns.<String>getList("recipient");
+ final var groupIdStrings = ns.<String>getList("group-id");
+
+ final var recipientIdentifiers = CommandUtil.getRecipientIdentifiers(m,
+ isNoteToSelf,
+ recipientStrings,
+ groupIdStrings);
+
+ final var isEndSession = ns.getBoolean("end-session");
+ if (isEndSession) {
+ final var singleRecipients = recipientIdentifiers.stream()
+ .filter(r -> r instanceof RecipientIdentifier.Single)
+ .map(RecipientIdentifier.Single.class::cast)
+ .collect(Collectors.toSet());
+ if (singleRecipients.isEmpty()) {
+ throw new UserErrorException("No recipients given");
+ }